Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | None |
Time | 2m |
CentOS Linux command to start / stop / restart SSHD service
- service command – Stop, start, restart or find the status of system services for CentOS v4.x/5.x/6.x only.
- chkconfig command – Turn on or off services on boot time CentOS v4.x/5.x/6.x only.
- systemctl command – Manage and start/stop/restart sshd on CentOS v7.x/8.x or above only (see CentOS 7.x/8.x commands here).
sshd service name on a CentOS Linux
The name of the service is also sshd and usually controlled by /etc/init.d/sshd script or service command or systemctl
CentOS turn on OpenSSH SSHD server on boot time command
The syntax is as follows to turn on SSHD on boot time for CentOS version 4.x/5.x/6.x or older:
## you must login as root user. In other words, try 'sudo -i' or 'su -' ## # chkconfig sshd on
For example, to turn off the SSHD service on boot time, enter:
# chkconfig sshd off
To see the current status of service in each run-level type:
# chkconfig --list sshd
Sample outputs:
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
CentOS start sshd service command
The syntax is as follows for CentOS version 4.x/5.x/6.x or older:
# service sshd start
OR
# /etc/init.d/sshd start
CentOS stop sshd service command
The syntax is for CentOS version 4.x/5.x/6.x or older:
Alert: Do not run the following command over ssh based session and you will end up getting ‘network connectivity lost’ error.
# service sshd stop
OR
# /etc/init.d/sshd stop
CentOS restart sshd service command
The syntax is for CentOS version 4.x/5.x/6.x or older:
# service sshd restart
OR
# /etc/init.d/sshd restart
CentOS find status of the sshd service command
The syntax is for CentOS version 4.x/5.x/6.x or older:
# service sshd status
OR
# /etc/init.d/sshd status
Sample session outputs from the above commands
Fig. 01: service and chkconfig command in action for CentOS version 4.x/5.x/6.x and older only
A note about CentOS version 7.x/8.x or above
CentOS Linux version 7.x and 8.x come with systemd as init. In other words, the above command may not work. You need to use the systemctl command to manage services on a CentOS Linux box. Hence, I recommend avoiding using the service command on the latest version of CentOS Linux. Let us see all commands and examples to restart sshd on CentOS 7.x or 8.x
Enable service at boot time
To enable SSHD service at boot time on CentOS version 7.x/8.x or above, run:
# systemctl enable sshd
Sample outputs:
Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to /usr/lib/systemd/system/sshd.service.
Start SSHD on CentOS version 7.x/8.x+ or above
# systemctl start sshd.service
Restart SSHD on CentOS version 7.x/8.x+ or above
# systemctl restart sshd.service
Stop SSHD on CentOS version 7.x/8.x+ or above
# systemctl stop sshd.service
Reload SSHD on CentOS version 7.x/8.x+ or above after config changes
# systemctl reload sshd.service
Want to get status SSHD on CentOS version 7.x/8.x+ or above?
Try the following systemctl command:
# systemctl status sshd.service
Sample outputs:
* sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2017-08-08 21:01:45 IST; 1min 5s ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 25701 (sshd) CGroup: /system.slice/sshd.service ??25701 /usr/sbin/sshd -D Aug 08 21:01:45 centos7-box systemd[1]: Starting OpenSSH server daemon... Aug 08 21:01:45 centos7-box sshd[25701]: Server listening on 0.0.0.0 port 22. Aug 08 21:01:45 centos7-box sshd[25701]: Server listening on :: port 22. Aug 08 21:01:45 centos7-box systemd[1]: Started OpenSSH server daemon.
Conclusion
You successfully learned how to start, stop, and restart the sshd server on a CentOS Linux version 4.x/5.x/6.x/7.x and 8.x. In short, use systemctl command for CentOS 7.x/8.x and service command for an older version. See the CentOS project page here and how to secure OpenSSH (SSHD) server for more info.
🐧 1 comment so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Hi
systemctl start httpd
systemctl stop httpd
systemctl restart httpd ===> service down and up
systemctl reload httpd ===> service not down only reading the configuration file service reload vs restart