How to set up and use OpenSSH on CentOS 7

Secure shell or SSH a protocol that allows users to connect to a remote system using a client-server architecture.

The login session is encrypted and very secure. Today we are going to show you how to set up and use OpenSSH on a Linux VPS using CentOS 7 as the operating system.

CentOS 7 is provided with packages openssh, openssh-server and openssh-clients… Package openssh requiresopenssl-libs installed on the system as it provides some very important cryptographic libraries.

The following command can be used for this purpose:

# yum install openssh openssh-server openssh-clients openssl-libs

After the packages are installed, you are ready to connect to the server via SSH. The default configuration file for the SSHd daemon is /etc/ssh/sshd_config and most of the settings for the daemon are defined in this file. Before making any changes, it is recommended that you make a copy of the original configuration file, so if you have any problems you can revert the changes back to default.

# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.orig

You can use a text editor of your choice to view and edit the configuration file. We will use nano because of its simplicity.

# nano /etc/ssh/sshd_config

The first thing you would like to change is the listening port number. Default SSH daemon listens on port 22 and for security reasons you can change the number to something else. Change the line:

Port 22


Port 2022

You can use a port number of your choice which is not used by any other service on the CentOS VPS. After you make your changes, you can save and close the file. In order for the changes to take effect, you must restart SSH daemon

# systemctl restart sshd.service

In order to further enhance security, it is recommended that you use a key based authentication. A key based authentication will allow you to connect to the server via SSH without using your user password on the system. Instead, you need to use SSH keys. For more information on how to login via SSH without a password using SSH keys we recommend that you read our dedicated tutorial.

SSH protocol allows other operations such as copying files between two remote hosts to be in an encrypted and secure manner. For this reason, you can use scp, a remote file copy program, and sftp which is an online file transfer program very similar to FTP. For more details on how to use scp and sftp you can read the instructions that are available at We’ll cover this topic in some of our next based Linux tutorials.

PS. If you liked this post, please share it with your friends on social networks using the buttons on the left side or just leave a comment below. Thank you in advance.