SSH key authentication

SSH-keys are used a lot in many applications such as git, to access an account without the need for username and password. It is also more safe since there is the need of actual data present in your pc, which cannot be "guessed", unlike many passwords.

Once created you can log in to the shell using your username and password for the first time. In order to set up ssh-key based authentication you just need to add your public key to the authorized_keys file in the .ssh folder.

First this guide will show you how to do that and in the second part there will be links on how to generate an ssh-key pair for those who want one.

Part 1: Create your SSH key(pair)

Creating SSH keys is a platform specific procedure.

For Windows users detailed instructions can be found at:
https://www.ssh.com/ssh/putty/windows/puttygen
For Linux, Mac, and Termux (Android) users detailed instructions can be found at:
https://www.ssh.com/ssh/keygen

On Linux or UNIX, ssh key pair can be generated with

$ ssh-keygen -t rsa

Part 2: Configure SSH key(pair) access

Assuming you are log into your shell and you see **<YourName>$**, press ls -a to show all the items in your home directory. Notice the **.ssh** folder, that is the one we want. Press cd .ssh to change into it and press again ls to see the **authorized_keys** file that we were looking for.

Time to open this file for editing, one way to do this is the command nano authorized_keys. The file should be empty, if it is not go to a new empty row and leave the cursor there for a moment.

$ nano .ssh/authorized_keys
$ chmod 700 $HOME
$ chmod 700 $HOME/.ssh
$ chmod 600 $HOME/.ssh/authorized_keys

Now let's go to our public key file in our pc, open it with any program and copy all the text you see starting from the //ssh-rsa// all the way to the e-mail at the end (including it). Select all the text (Ctrl+A), copy all the text either with Ctrl+C, either with right click and copy.

  • Important:** __Make sure it is the public key and it begins with //ssh-rsa// !!__

Having the key copied in the clipboard we can change back to the ircnow shell and press right click and paste or Ctrl+Shift+V, and the text should appear on the new row in the file.

Now let's close the editor, if you used nano the command is Ctrl+x and press Yes at the prompt that asks you whether to save or discard the changes.

Next time you ssh into your shell there will be no need to insert the password, if you added a passphrase to you key during creation, that might be requested instead, otherwise you will log in directly!