HowTo: RaspberryPi – Login via SSH without password prompt

The more you become involved with all this IT/software/programming stuff, the faster you will discover that the possibilities of related automation make you dreadfully lazy.
One of those moments in which one thinks of a possibility for automation or simplification is, if one logs in for the 48th time via puTTy in his RaspberryPi (or Linux system).

Because especially with so often repetitive processes you can save a lot of time, if you take the trouble to abbreviate this process in the future.

How you can spare yourself the input of username and password for your RaspberryPi in the future is explained in the following article.

Hints for our lovely english readers: Basically, many of the articles on Nerdiy.de are translations from the original german articles. Therefore, it may happen here and there that some illustrations are not available in english and that some translations are weird/strange/full of mistakes or generally totaly wrong. So if you find some obvious (or also not obvious) mistakes don't hesitate to leave us a hint about that in the comment section. 
Also please don't get confused, that instead of a "dot" often a "comma" is used as decimal separator. 🙂


Safety instructions

I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/sicherheitshinweise/


Requirements

Helpful Articles:

Before you start with this article, you should have prepared the RaspberryPi so far that it can be reached via the network and controlled by SSH.
RaspberryPi – Setting up for Nerdiys!
RaspberryPi – The first configuration
RaspberryPi – Controlling the RaspberryPi via SSH

Required tools:
-none-

Required material:

In the following list you will find all the parts you need to implement this article.


Log in via SSH on the RaspberryPi

To get started, you first need to log in to RasPi with SSH on Putty. How to do it is described in the article RaspberryPi - Controlling the RaspberryPi via SSH.

After entering your username and password you can start to enter the first commands.

Create an SSH key pair

In order for the login to work in a remote system without password entry, you must exchange the keys that encrypt your connection to the system in advance and thus make known to both systems.

To generate these just enter the following command.

ssh-keygen -t rsa -b 4096
To create the SSH key pair, enter the command “ssh-keygen -t rsa -b 4096”.
This will start your RaspberryPi (or other Linux system) to create a key pair. This can take a while, depending on the computing power. So do not hesitate and wait. If in doubt, a perfect opportunity to get a new cup of coffee. 🙂
After the generation of the key pair is complete, you can choose where you want to save the generated files. Normally, you do not need to change the location and confirm with “Enter”.
Then you will be asked if you want to create a password for the private part of the key pair. If you do this you have to enter this password every time you log in to the remote system. If you do not specify a password here, you can log in from this system without entering a password on the remote system. Please keep in mind that this can be a security risk. If you do not set a password, a potential attacker will have direct access to two systems. Here you have to choose between the luxury of no password and security.
After entering (or not entering) the password, the entered password must be confirmed again.
Then the creation of the key pair is completed. You will see the fingerprint and the random art of the key pair. This facilitates the comparison – otherwise encrypted data – for humans.

Exchange of the public key

Now you have to finally copy the newly generated public key of the key pair on the remote system (for example, another RaspberryPi). To do this, first switch to the folder containing the key pair just created with the command “cd + /. Ssh”.
cd ~/.ssh
From there you copy the public key to the remote system with the command “ssh-copy-id -i id_rsa.pub pi @ rasPi”. It is important that you replace the domain name (in this case “rasPi”) with the domain name of your remote system.
ssh-copy-id -i id_rsa.pub pi@rasPi
Since you also build an SSH connection to the remote system during this operation, you must confirm the following demands with …
…”yes” and…
… also enter the login password of the remote system.
Once you have done that, you will receive the message that the public key of your key pair has been copied to the remote system.
Now you can test if everything works by entering the command “ssh pi@rasPi”. Again, “rasPi” must be replaced by the domain name of your RaspberryPi’s (or other Linux system). If you have not entered a password for your private key, then you automatically land in the console of the remote system.

CAUTION: Keep in mind that you are opening a potential security hole on one of your systems. Use strong passwords – at least on the system you log in to the remote system – and handle them responsibly.


I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂

Fab

P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂

Buy Me a Coffee at ko-fi.com

Leave a Reply

Your email address will not be published. Required fields are marked *