How to access a server via SSH without using password?

Asked

Viewed 6,510 times

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 performing connection without using user and password, as this is possible?

  • I found an English tutorial on how to do this on linux, I don’t know if it really picks up. Linuxhorizon and Page Translation with Google Translator

  • Simple: Enter your public key in the authorized_keys of the server in question.

  • Since I did not write this post and there should not be a response with only the link, take a look at this address: http://www.tonido.com/blog/index.php/2009/02/20/ssh-without-password-using-putty/#. Uupbnnddv_g

3 answers

6


Access is done using public/private keys.

First you need to generate your private key (If you use git you 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

Done this, the next time you log into the server ssh user@host, no need to add password.

  • 1

    It works well for Linux. But the question says that the client is using Putty (Windows)

  • @Andre in the case of Putty, just use the command pscp on the site of scp. Remember that the Putty directory must be registered in the windows PATH environment variable so that this is available at the prompt.

  • 1

    ssh-keygen exists in Windows? I don’t think there is... The question is about Putty (although it is marked as Linux and ssh) and the answers should also be. I put a comment with a link to a tutorial in the question. I think it will help a little more who asked than information on how to do this on Linux.

  • 1

    @Andre The fact of asking contain Putty went unnoticed when I posted the answer, since I was seeing the [Linux] tag. I believe your comment correctly answers the question.

  • "After generating the private key, send it to the server" I think you mean "send the key public to the server, "no? (at least your code is sending the file .pub)

  • @mgibsonbr Thank you, corrected the typo.

Show 1 more comment

1

Consider that you have two servers: SERVIDOR1 and SERVIDOR2.

In SERVIDOR1, generate 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 

In SERVIDOR2, create the ~/ssh folder inside the home and create the authorized_keys file

cd 
mkdir ~/.ssh
touch .ssh/authorized_keys

In SERVIDOR1, display the created key.

cat .ssh/id_rsa.pub 

Copy and paste the generated key result

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuo0vDDu7vMhc7hum1bgNool+IMfPrt77dZOVAY9fIm1jm8oL57wXXMUe/lcJox+f3YkvGxZMLRUbvM4

Go back to SERVIDOR2, get . ssh/authorized_keys , and paste the key contents. Then give a CHMOD 600.

 cd
 nano .ssh/authorized_keys
 chmod -v 600 .ssh/authorized_keys

Ready! Now you can do SERVIDOR2 pro SERVER 1 SSH without typing 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: https://www.homehost.com.br/blog/ssh-chave-remota-sem-pedir-senha/

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.