If you access the same computer through SSH on a regular basis, or want to access a machine through SSH in a script, then you don’t want to have to worry about passwords. Luckily, there is a way to grant SSH access without a password while remaining secure. For a quick and easy fix, download and run this bash script.
For this we will assume that you’re connecting to the computer remote with the user r from your computer with the user you are currently logged in as [username].
First, we need to generate a key:
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ""
If asked if you want to overwrite the file, press n. You will now have a file /home/[username]/.ssh/id_rsa.pub.
Next, we add the public key to the list of authorized keys on remote (you will need to enter your password twice):
cd && ssh r@remote mkdir -p .ssh && cat .ssh/id_rsa.pub | ssh r@remote 'cat >> .ssh/authorized_keys'
And that’s it. You should now be able to
ssh r@remote from your user on your computer without having to enter a password.