In this article we will take a look at how to setup authentication with ssh keys. In our example we have Server names s1 and workstation named w1. Our goal is to setup secure ssh authentication without password. This considered to be a more secure way plus it comes really handy when you need to use ssh copy in the script.
The keys will be generated on workstation and then public key will be copied to server.
1. Run the following command on w1 (workstation from which you will be accessing your server)
ssh-keygen -t rsa
2. Next we will run the following command which will copy public key to users bob hidden /home/bob/.ssh/authorized_keys
3. Finally you should be able to login without using password.
Make sure correct permutations applied to .ssh folder and to files inside.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
You can also run a debug mode in some cases it can be very helpful.
ssh -vvv -o PreferredAuthentications=publickey root@"your ip address" -v