How To Enable SSH On CentOS 7

This article will tell you how to install, start, stop, restart OpenSSH server on CentOS. It will also tell you how to connect to it through ssh client software.

1. How To Install OpenSSH Server On CentOS.

  1. Open terminal and run command yum install openssh-server openssh-clients to install OpenSSH server and clients with root user.
    # su
    # yum install openssh-server openssh-clients
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
     * base:
     * extras:
     * updates:
    Package openssh-server-7.4p1-21.el7.x86_64 already installed and latest version
    Package openssh-clients-7.4p1-21.el7.x86_64 already installed and latest version
    Nothing to do

2. How To Start, Stop, Restart And Get OpenSSH Server Status.

  1. Run command # systemctl status sshd to get OpenSSH server status.
    # systemctl status sshd
    ● sshd.service - OpenSSH server daemon
       Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
       Active: active (running) since Wed 2020-03-11 14:38:25 CST; 3s ago
         Docs: man:sshd(8)
     Main PID: 4687 (sshd)
        Tasks: 1
       CGroup: /system.slice/sshd.service
               └─4687 /usr/sbin/sshd -D
    Mar 11 14:38:25 systemd[1]: Starting OpenSSH server daemon...
    Mar 11 14:38:25 sshd[4687]: Server listening on port 22.
    Mar 11 14:38:25 sshd[4687]: Server listening on :: port 22.
    Mar 11 14:38:25 systemd[1]: Started OpenSSH server daemon.
  2. Run command # systemctl start sshd to start OpenSSH server.
    # systemctl start sshd
  3. Run command # systemctl stop sshd  to stop OpenSSH server.
    # systemctl stop sshd
  4. Run command # systemctl restart sshd to restart OpenSSH server.
    # systemctl restart sshd

3. Configure OpenSSH As OS Service.

  1. Below command will start openSSH as a service automatically after CentOS start.
    # systemctl enable sshd
  2. Below command will disable openSSH automatically started after CentOS start.
    # systemctl disable sshd

4. OpenSSH Server Configuration File.

  1. The openSSH server configuration file is located at /etc/ssh/sshd_config. You can change it to make your openSSH server more secure. Run command # vim /etc/ssh/sshd_config to edit it.
  2. You can change the default port number by edit #Port 22 line to Port 66.
  3. You can disallow root login by change #PermitRootLogin yes to PermitRootLogin no.
  4. You should restart the openSSH service after update it’s configuration file.
    service sshd restart

5. Connect To OpenSSH Server With SSH Client.

  1. If you use MacOS or Linux you can run command ssh user-name@ssh-server-ip in a terminal to login to the ssh server.
  2. If you use windows, you can use putty as the ssh server client tool.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.