This week’s tip: SSH Keys (or I do not like typing my long cryptic password everytime I need to access my server)
If you’ve been following my other tips you might remember that ssh uses different authentication options, credentials, domain login, password, you name it, one of these is via ssh keys.

SSH Keys

Imagine your car. You’re used to using a key to open the door and start the engine once or twice per day. How about if you were a messenger that has to do this 40, 50, 60 times per day, it gets tiresome, wouldn’t it be great for the car to open the door and automatically start the engine when it senses that it’s you?
The same principle bit different.
(Please note, that this tutorial is aimed to Linux to Linux connections, putty has a local key generator that could be technically used as the same.)
1. Creating the keys and their folder
First, create the local folder, type mkdir /home/$USER/.ssh (type it just like that)
Then the key: ssh-keygen -t dsa (anything it asks just press enter)
2. Copying the key to the remote server
Move to the ssh folder: cd /home/$USER/.ssh
Copy the file: scp yourremoteuser@remoteip:./
3. Adding the key on the remote server
First, log in to the remote server via ssh as usual
Then add the key to the remote server’s key list:
cd /home/remoteusername/
mkdir .ssh
mv .ssh/
cd .ssh/
check if there is a file named authorized_keys, if not then create it:
touch authorized_keys
finally, add the key:
cat >> authorized_keys
4. Activating the keys used on the remote server.
Type: nano /etc/ssh/sshd_config
And look for AuthorizedKeysFile and make sure that it’s uncommented (meaning that there is no # symbol before that word) and that next to it says .ssh/authorized_keys
Save (Ctrl + x) and restart the ssh service.
5. Testing.
Log out of the remote server and try to log in again, this time it will not ask for a password.

Comments are closed.