How to access a server via SSH without using a password?

7

I have to connect a Linux server via SSH, using Putty as a client, many times a day and every time I need to put user and password. I have seen a person making connection without using username and password, how is this possible?

    
asked by anonymous 30.01.2014 / 14:13

3 answers

6

Access is done using public / private keys.

First you will need to generate your private key (If you use git you should probably already have one)

ssh-keygen -t rsa

After generating the public key, send it to the server

scp ~/.ssh/id_dsa.pub USUARIO_REMOTO@SERVIDOR:/home/USUARIO_REMOTO/.ssh/

Finally, enable the key on the server.

cd ~/.ssh/
cat id_dsa.pub >> authorized_keys
chmod 644 authorized_keys

After this, the next time you enter the server ssh user@host , you do not need to add the password.

    
30.01.2014 / 14:58
1

This is common in AWS, when you use a .pem file to log in to the machine. The command is something like this:

# ssh -i ~/.<usuario>.pem <user>@<host>

... and you are already logged in.

Take a look at this article to see if it helps: link

    
30.01.2014 / 14:22
1

Consider that you have two servers: SERVER1 and SERVER2.

On SERVER1, generate the RSA key:

cd
ssh-keygen -t rsa

Expected result for this command:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/usuario/.ssh/id_rsa): 
Created directory '/home/usuario/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/usuario/.ssh/id_rsa.
Your public key has been saved in /home/usuario/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:xx:79:xx:9f:96:xx:3b:ad:xx:58:37:bc:37:e4 usuario@S1

Provide the correct permissions:

chmod -v 600 .ssh/id_rsa 

On SERVER2, create the ~ / ssh folder inside the home and create the authorized_keys file

cd 
mkdir ~/.ssh
touch .ssh/authorized_keys

On SERVER1, display the created key.

cat .ssh/id_rsa.pub 

Copy and paste the result of the generated key

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuo0vDDu7vMhc7hum1bgNool+IMfPrt77dZOVAY9fIm1jm8oL57wXXMUe/lcJox+f3YkvGxZMLRUbvM4

Return to SERVER2, exit the .ssh / authorized_keys file, and paste the contents of the key. Then give CHMOD 600.

 cd
 nano .ssh/authorized_keys
 chmod -v 600 .ssh/authorized_keys
Ready! Now you can SSH from SERVER2 to SERVER 1 without typing the password.

root@servidor:~# ssh 177.10.20.30
The authenticity of host '[servidor1]:64413 ([177.XX.XX.101]:22)' can't be established.
RSA key fingerprint is SHA256:UbCvey971joqLCsFUc3WBEyTNVEFd2/1Irh6RWMo7xM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[servidor1]:22' (RSA) to the list of known hosts.
Last login: Mon Jun 20 13:01:19 2016 from 186.242.115.87

You can read this full article in more detail: link

    
22.06.2016 / 15:41