CentOS 7 – SSH key-based authentication

How to configure nginx for Magento 2

As we have noticed by using SSH every time, we need to type the password, which is not something recommended in many security policies. This is where we will use the SSH feature to use authentication by using public/private keys.

SSH provides a tool for creating public/private keys to use for remote connection authentication, without the need to use a password. How do we do that? It’s simple. For this test example we are going to create a new RSA key, a little bit more secure than the usual (we can create different types of keys such as dsa, ecdsa, ed25519):


$ ssh-keygen –t rsa -b 2048 -v

Then we follow the steps presented by the command. For a default installation, we can just keep typing Enter. Otherwise, we can always add some kind of passphrase to make it more secure. We may need to specify the key file name so we can use it later.

Then we need to copy the newly created keys file to the host that we want to connect to. There are two ways of doing this. The traditional way, which is to literally copy the key file into the server that we want to remote connect to without using a password. Where we need to put the file in the subfolder .ssh located at the current user folder. Or, we can simply use the ssh-copy-id command that does the same job without the pain:


$ ssh-copy-id user1@server1.packt.co.uk

Then we need to type the password for the last time.

After that, any SSH remote connection or file transfer can be done without the need for a password.

Source: https://www.digitalocean.com/

Comments are closed.