Ssh provides secure remote connections to the remote systems. It is defacto protocol used to manage Linux and networking systems remotely via command line. Ssh provides a lot of extra features which makes it useful for different purposes. For example we can copy files to remote and local system via ssh with a secure manner. In order to make things straightforward we can use passwordless key based authentication for ssh protocol.
List Public and Private Keys On Local system For Client
In some cases there may exist public and private keys all ready. The default location for ssh user public and private keys is /home/user/.ssh
. So we will list whether the directory and keys exist. We will use ls
command for this.
$ ls -l /home/ismail/.ssh/

As we can see there is no ssh public or private key in this example.
Create Public and Private Keys On Client
The first step is creating public and private key pairs on the client system.Public key is copied to the remote system and private key is hold on the local system. Private key should be only known by the local system user. We will use ssh-keygen
command. This command will create keys named id_rsa.pub
and id_rsa
.
$ ssh-keygen

Copy Public Key to the Server with ssh-copy-id
We will use ssh-copy-id
command in order to copy ssh public key to the remote system. We will provide the remote system IP address and if the remote user is different from local user the username. In this example we use current user.
$ ssh-copy-id 192.168.43.129

As we can see from output 1 key is added to the remote system.
Copy Public Key to the Server with ssh echo
We have alternative way to copy key to the remote other than ssh-copy-id
. As stated previously ssh
provides different features which makes system administrators life easy. We can run commands on remote system without an interactive shell. We will use this feature with echo
command where our key will be copied to the remote system.
$ cat .ssh/id_rsa.pub | ssh 192.168.43.129 'cat >> .ssh/authorized_keys'
Connect with Passwordless
Now we have completed all steps. We can simply connect remote system passwordless with ssh just running following command.
$ ssh 192.168.43.129

1 thought on “How To Login To Linux with Passwordless via SSH with Key Based Authentication?”