Logon to Linux System using SSH Private Key

November 30, 2019

You can use your public / private key pair to login to remote Linux systems without needing to remember the remote accounts password all the time.

If you already have a SSH public / private key pair on the local computer then you can skip the next step. If however you have not got one then you will need to create a pair by entering the following command:-


Now that you have a public / private key pair it can be copied to your remote Linux system using ssh-copy-id. Once this has been done you will be able to login to the remote system using your private key. This has the advantage that you do not have to remember a lot of different passwords for various machines.

Login to the Linux / OSX system you will be using normally (your local computer) and then enter the following command.

ssh-copy-id remote_user@remote_computer

Enter the password for the remote_user when prompted. Assuming that you have entered the password correctly your public key will be copied to the users account on the remote computer. You should now be able to login to that computer using your private key.

ssh remote_user@remote_computer

If you have your private key password protected (which is a good idea) then you will be prompted to enter its password.

You might be wondering where the benefit is since you still have to enter a password – the benefit comes from being able to use the same process with lots of different accounts on different machines … you now only have a single password to remember.

Tags: linux