HowTo: Raspberry Pi – Login via SSH without password query

The more you get involved with all this IT/software/programming stuff, the quicker you'll realize that the possibilities of the associated automation make you terribly lazy.
One of those moments when you think of a possibility for automation or simplification is when you log into your RaspberryPi (or Linux system) for the 48th time via puTTy.

Especially when processes are repeated so often, you can save a lot of time if you make the effort to shorten this process in the future.

How you can save yourself having to enter your username and password for your RaspberryPi in the future is explained in the following article.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
Before you start with the article you should prepare the RaspberryPi so that it is accessible via the network and controllable via SSH.

The following three articles describe what needs to be done to prepare the RaspberryPi:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH

Required material:
-no-

Required material:

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


Log in to the RaspberryPi via SSH

To start, you must first log in to the Rasp Pi with Putty via SSH. How to do this is in the article RaspberryPi - Control the RaspberryPi via SSH described.

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

Generate an SSH key pair

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

To do this, they have to be created first. This can be done with the following command.

ssh-keygen -t rsa -b 4096
To create the SSH key pair, enter the command “ssh-keygen -t rsa -b 4096”.
Your RaspberryPi (or other Linux system) will then start creating a key pair. Depending on your computing power, this can take a while. So don't despair 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 don't need to change the storage location, so confirm with “Enter”.
You will then be asked whether you want to create a password for the private part of the key pair. If you do this, you will have to enter this password every time you log in to the remote system. If you do not set a password here, you can log in to the remote system from this system without entering a password. Please keep in mind that this can be a security risk. If you don't set a password, a potential attacker has direct access to two systems. Here you have to decide between the luxury of not having to enter a password and security.
After entering (or not entering) the password, the entered password must be confirmed again.
The creation of the key pair is then completed. You will be shown the fingerprint and the random type of the key pair. This makes it easier for people to compare the otherwise encrypted data.

Public key exchange

Now, last but not least, you have to copy the public key of the key pair you just created to the remote system (for example another Raspberry Pi). To do this, first use the command “cd +/.ssh” to go to the folder that contains the key pair you just created.
cd ~/.ssh
From there, copy the public key to the remote system using 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 establish an SSH connection to the remote system with this system, you have to answer the following questions with...
…”yes” confirm and…
…enter the login password of the remote system.
Once you have done this, you will receive a message that the public key of your key pair has been copied to the remote system.
Now you can test whether everything works by entering the command “ssh pi@rasPi”. Here too, “rasPi” must be replaced by the domain name of your RaspberryPi (or other Linux system). If you have not entered a password for your private key, you will automatically end up in the console of the remote system.

ATTENTION: Please keep in mind that you are opening a potential security hole on one of your systems. Use strong passwords – at least on the system from which you log into the remote system – and use them responsibly.


Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS 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 think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.