Table of Contents

Automate SSH Login Using Ssh Agent And Sshpass

In this tutorial, I will show you how to automate the ssh login process. To run these commands, either you should login as root or should have sudo user privileges.

ssh using ssh-add

Assuming you have private key in ~/.ssh area.

In my case, ~/.ssh/id_rsa.pub and ~/.ssh/id_rsa keys are present in ~/.ssh directory.

Now do following...

eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa

Now you can login using following command without password.

ssh root@remote_host_address

Note - The above process will work only for the current session. If you exit and login again, you will have to redo the above steps.

ssh using sshpass

Another way to automate the ssh login is using sshpass.

Install sshpass

sudo yum -y install sshpass

If you have public and private key set with passphrase, then run following command in your zsh or bash shell...

sshpass -p ''<your_passphrase>" -P 'Enter passphrase for key' ssh -i ~/.ssh/id_rsa root@remote_host_address

If you have only the password enabled login, then run following...

sshpass -p '<your_password>' ssh root@remote_host_address

Related Posts

1
2
3
4