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.
- Open terminal and run command yum install openssh-server openssh-clients to install OpenSSH server and clients with root user.
# su Password: # yum install openssh-server openssh-clients Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.bit.edu.cn * extras: mirror.bit.edu.cn * updates: mirror.bit.edu.cn 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.
- 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) man:sshd_config(5) Main PID: 4687 (sshd) Tasks: 1 CGroup: /system.slice/sshd.service └─4687 /usr/sbin/sshd -D Mar 11 14:38:25 192.168.0.106 systemd[1]: Starting OpenSSH server daemon... Mar 11 14:38:25 192.168.0.106 sshd[4687]: Server listening on 0.0.0.0 port 22. Mar 11 14:38:25 192.168.0.106 sshd[4687]: Server listening on :: port 22. Mar 11 14:38:25 192.168.0.106 systemd[1]: Started OpenSSH server daemon.
- Run command # systemctl start sshd to start OpenSSH server.
# systemctl start sshd
- Run command # systemctl stop sshd to stop OpenSSH server.
# systemctl stop sshd
- Run command # systemctl restart sshd to restart OpenSSH server.
# systemctl restart sshd
3. Configure OpenSSH As OS Service.
- Below command will start openSSH as a service automatically after CentOS start.
# systemctl enable sshd
- Below command will disable openSSH automatically started after CentOS start.
# systemctl disable sshd
4. OpenSSH Server Configuration File.
- 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.
- You can change the default port number by edit #Port 22 line to Port 66.
- You can disallow root login by change #PermitRootLogin yes to PermitRootLogin no.
- You should restart the openSSH service after update it’s configuration file.
service sshd restart
5. Connect To OpenSSH Server With SSH Client.
- 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.
- If you use windows, you can use putty as the ssh server client tool.