Automatic connection with SSH keys

There is an option to connect to SSH without passwords by using keys.

Creating the keys is a one-time operation that will allow future connection without using a password. For clarification, we will refer to the "host machine" as the machine from which the SSH connection is made, and the "remote machine" as the machine we are trying to connect to through SSH.

Creating keys in Windows

1. Download the PuttyGen application from:

https://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe

2. Run the program and click Generate:

3. During the process, as you move the mouse cursor randomly over the empty areas in the window, you will be able to see the Progress Bar fill up.

4. After the Progress Bar fills and after a short wait, we get the following window:

5. The public key appears under Public key for pasting into OpenSSH authorized_keys file. Mark it all and copy it.

6. Press Save private key to save the private key.

7. Connect to the remote machine using SSH. There, Edit the file ~ / .ssh / authorized_keys

8. Paste in a new line the public key that we copied above.

9. Close the SSH and open Putty.

10. After entering the address of the remote machine, on the left side of the window select Connection> SSH> Auth.

11. Click on Browse and select the private key you have saved above.

12. Clicking Open will open an SSH connection to the remote machine, in addition to a request for user name.

13. If everything went well, you will be able to connect immediately to the shell of the remote machine, without entering a password.

Create keys in Linux / Unix / Android / Mac

1. Run ssh-keygen on the terminal of the host machine.

2. You will be asked to choose a path, and passphrase. In any case, you should not insert anything but press enter until the process is finished.

3. At the end of the process, we will get two files: ~ / .ssh / id_rsa ~ / .ssh / id_rsa.pub The first is the public key and the other is the private key.

4. Open and copy the content of the file: ~ / .ssh / id_rsa.pub

5. Connect to the remote machine using SSH. There, edit the file: ~ / .ssh / authorized_keys

6. Paste the public key you copied above into a new line.

7. Exit the SSH connection and edit at the host machine the file:

~/.ssh/config

8. Add the lines Host {remote_ip} IdentityFile ~ / .ssh / id_rsa

Where {remote_ip} should be replaced with the ip address of the remote machine.

9. If everything went well, you will be able to connect immediately to the shell of the remote machine, without entering a password.


RECENT POST