Pesquisar neste blog

quinta-feira, 20 de novembro de 2008

SSH sem senha entre Servidores

Criando a chave rsa

[root@servidor01 .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):

Apenas tecle enter duas vezes

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
81:86:21:dd:ec:97:c2:27:d3:dd:16:7c:18:ca:cc:d5 root@servidor01.dominio.net

[root@servidor01 .ssh]# ls -l
total 12
-rw-------  1 root root  883 Nov 20 05:59 id_rsa
-rw-r--r--  1 root root  232 Nov 20 05:59 id_rsa.pub
-rw-r--r--  1 root root 3552 Oct 24 09:14 known_hosts

Copiar a chave pública para o servidor 2

[root@servidor01 .ssh]# scp id_rsa.pub servidor02.dominio.net:/root/.ssh/
root@servidor02.dominio.net's password:
id_rsa.pub                                  100%  232     0.2KB/s   00:00

[root@servidor01 .ssh]# ssh servidor02.dominio.net
root@servidor02.dominio.net's password:
Last login: Thu Nov 20 08:46:00 2008 from servidor01
[root@servidor02 ~]#
[root@servidor02 ~]# cd .ssh/
[root@servidor02 .ssh]# ls -la
total 24
drwx------  2 root root 4096 Nov 20 08:52 .
drwxr-x---  7 root root 4096 Nov 20 08:46 ..
-rw-r--r--  1 root root  232 Nov 20 08:52 id_rsa.pub
-rw-r--r--  1 root root 2022 Jun 13 14:42 known_hosts

Adicionando a chave pública ao arquivo authorized_keys

[root@servidor02 .ssh]# cat id_rsa.pub > authorized_keys
[root@servidor02 .ssh]#
[root@servidor02 .ssh]# logout
Connection to servidor02 closed.

Testando conexão ssh sem senha

[root@servidor01 .ssh]#
[root@servidor01 .ssh]# ssh servidor02
Last login: Thu Nov 20 08:53:11 2008 from servidor01
[root@servidor02 ~]#
[root@servidor02 ~]# logout


Pronto e sem mistério.


Agora podemos executar cópia de arquivos e executar comandos remotamente neste servidor sem o uso de senha.




Nenhum comentário: