CentOS Linux: Start / Stop / Restart SSHD Command

Posted on in Categories , , , last updated August 8, 2017

I am a new CentOS Linux server user. How can I start, stop, or restart the OpenSSH (SSHD) server on a CentOS Linux? How can I start SSHD on boot time on a CentOS Linux? How can I start/stop/restart SSHD on boot time on a CentOS Linux 7.x?

You need to use the following two commands:

  1. service command – Stop, start, restart or find the status of system services for CentOS v4.x/5.x/6.x only.
  2. chkconfig command – Turn on or off services on boot time CentOS v4.x/5.x/6.x only.
  3. systemctl command – Manage and start/stop/restart sshd on CentOS v7.x or above only.

sshd service name a CentOS Linux

The name of the service is also sshd and usually controlled by /etc/init.d/sshd script or service command.

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:

# chkconfig sshd on

To turn off 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

A note about CentOS version 7.x or above

To enable SSHD service at boot time on CentOS version 7.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.

To start SSHD on CentOS version 7.x+ or above

# systemctl start sshd.service

To restart SSHD on CentOS version 7.x+ or above

# systemctl restart sshd.service

To stop SSHD on CentOS version 7.x+ or above

# systemctl stop sshd.service

To reload SSHD on CentOS version 7.x+ or above after config changes

# systemctl reload sshd.service

To get status SSHD on CentOS version 7.x+ or above

# 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.

Sample session outputs from the above commands

Fig. 01: service and chkconfig command in action
Fig. 01: service and chkconfig command in action for CentOS version 4.x/5.x/6.x and older only

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

1 comment

  1. 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 :

Leave a Comment