GNU/Linux >> Linux Esercitazione >  >> Linux

Configurazione dell'autenticazione basata su chiave SSH da openSSH a SSH2

Gli articoli precedenti (configurazione da openSSH a openSSH, configurazione da SSH2 a SSH2) spiegano come impostare l'autenticazione basata su chiave su la stessa versione di ssh per eseguire ssh e scp senza inserire la password. Questo articolo spiega come configurare l'autenticazione basata su chiave SSH tra diverse versioni di SSH (da openSSH a SSH2) per eseguire ssh e scp senza inserire la password.

1. Verifica la versione SSH dell'host locale e dell'host remoto.

In questo esempio, l'host locale è in esecuzione su openSSH e l'host remoto è in esecuzione su SSH2.

[local-host]$ ssh -V
OpenSSH_5.0p1, OpenSSL 0.9.8g 19 Oct 2007

[remote-host]$ ssh -V
ssh: SSH Secure Shell 3.2.9.1 (non-commercial version) on i686-pc-linux-gnu
[remote-host]$ ls -l /usr/local/bin/ssh
lrwxrwxrwx  1 root root 4 Mar 10 22:04 /usr/local/bin/ssh -> ssh2

2. Genera coppia di chiavi sull'host locale usando ssh-keygen

[local-host]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):<Hit enter>
Enter passphrase (empty for no passphrase): <Enter your passphrase here>
Enter same passphrase again:<Enter your passphrase again>
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is:
3b:2a:d2:ac:8c:71:81:7e:b7:31:21:11:b8:e8:31:ad jsmith@local-host

La chiave pubblica e la chiave privata sono generalmente archiviate nella cartella .ssh nella directory home. In questo esempio, è in /home/jsmith/.sshd. Non condividere la chiave privata con nessuno.

Per impostazione predefinita, ssh-keygen su openSSH genera una coppia di chiavi RSA. Puoi anche generare una coppia di chiavi DSA utilizzando:ssh-keygen -t dsa comando.

3. Converti la chiave pubblica openSSH in chiave pubblica SSH2.

Sull'host locale che esegue openSSH, converti la chiave pubblica openSSH nella chiave pubblica SSH2 utilizzando ssh-keygen come mostrato di seguito.

[local-host]$ ssh-keygen -e -f ~/.ssh/id_rsa.pub > ~/.ssh/id_rsa_ssh2.pub

4. Installa la chiave pubblica sull'host remoto che esegue SSH2.

Crea un nuovo file di chiave pubblica sull'host remoto e copia e incolla la chiave SSH2 convertita dall'host locale.

[remote-host]$ vi ~/.ssh2/local-host_ssh2_key.pub 
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "2048-bit RSA, converted from OpenSSH by jsmith@local-host"
DDDDB3NzaC1yc2EAAAABDmbrdomPh9rWfjZ1+7Q369zsBEa7wS1RxzWRQ0Bmr9FSplI
3ADBEBC/6cbdf/v0r6Cp5y5kusP07AOzo2F7MBDSZBtS/MbYJiIxvocoaxG2bQyz3yYjU
YcpzGMD182bnA8kRxmGg+R5pVXM34lx3iSSgd8r3RzZKnDpEvEInnI7pQvUBoEbYCXPUeZ
LQvQAkz6+Pb6SsNp-dop/qgv9qyfbyMz1iKUZGadG146GtanL5QtRwyAeD187gMzzrGzMFP
LWjdzWpGILdZ5gq7wwRpbcXFUskVrS2ZjDe676XlTN1k5QSZmSYUuttDdrjB5SFiMpsre8
a7cQuMS178i9eDBEC==
---- END SSH2 PUBLIC KEY ----

Aggiungi il nome del file della chiave pubblica sopra al file di autorizzazione sull'host remoto come mostrato di seguito.

[remote-host]$ vi ~/.ssh2/authorization 
Key local-host_ssh2_key.pub

5. Verifica l'accesso dall'host locale all'host remoto utilizzando l'autenticazione con chiave SSH2.

[local-host]$ ssh -l jsmith remote-host <You are on local-host here>
The authenticity of host 'local-host' can't be established.
DSA key fingerprint is a5:f6:2e:e6:a9:b2:7b:0e:e7:ae:cb:6c:7b:f5:6d:06.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'local-host' (DSA) to the list of known hosts.
Enter passphrase for key '/home/jsmith/.ssh/id_rsa': <Enter your passphrase here>
Last login: Sat Jun 21 2008 23:13:00 -0700 from 192.168.1.102
No mail.
[remote-host]$ <You are on remote-host here>

Esistono due modi per eseguire ssh e scp senza inserire la password:

  1. Nessuna passphrase. Durante la creazione di una coppia di chiavi, lasciare vuota la passphrase. Utilizzare questa opzione per l'elaborazione batch automatizzata. per es. se stai eseguendo un lavoro cron per copiare file tra macchine questa è un'opzione adatta. Puoi saltare i passaggi successivi per questo metodo.
  2. Utilizza passphrase e agente SSH. Se stai usando ssh e scp in modo interattivo dalla riga di comando e non vuoi usare la password ogni volta che esegui ssh o scp, non consiglio l'opzione precedente (nessuna passphrase), poiché hai eliminato un livello di sicurezza nell'autenticazione basata su chiave ssh. Invece, usa la passphrase durante la creazione della coppia di chiavi e usa SSH Agent per eseguire ssh e scp senza dover inserire la password ogni volta come spiegato nei passaggi seguenti.

6. Avvia l'agente SSH sull'host locale

L'agente SSH verrà eseguito in background per conservare le chiavi private ed eseguire ssh e scp senza dover immettere più volte la passphrase.

[local-host]$ ssh-agent $SHELL

7. Carica la chiave privata nell'agente SSH sull'host locale.

[local-host]$ ssh-add
Enter passphrase for /home/jsmith/.ssh/id_rsa:<Enter your passphrase here>
Identity added: /home/jsmith/.ssh/id_rsa (/home/jsmith/.ssh/id_rsa)

8. Esegui SSH o SCP a casa remota dall'host locale senza inserire la password.

[local-host]$<You are on local-host here>

[local-host]$ ssh -l jsmith remote-host
Last login: Sat Jun 07 2008 23:03:04 -0700 from 192.168.1.102
No mail.
<ssh did not ask for passphrase this time>
[remote-host]$ <You are on remote-host here>

Linux
  1. Come configurare l'autenticazione basata su chiave SSH in Linux

  2. Ssh - Riceve ancora una richiesta di password con Ssh con l'autenticazione con chiave pubblica?

  3. Come utilizzare Sftp su un sistema che richiede Sudo per l'accesso root e l'autenticazione basata su chiave Ssh?

  4. Converti la chiave privata Openssh in una chiave privata Ssh2?

  5. Guida completa per la configurazione dell'autenticazione basata su chiave SSH2

Come configurare le chiavi SSH – Sistema operativo Windows?

Comando SSH

Come impostare l'autenticazione a più fattori per SSH in Linux

Come configurare l'accesso senza password SSH in AlmaLinux

Come impostare l'autenticazione basata su chiave Ssh per Github utilizzando il file ~/.ssh/config?

Esegui SSH e SCP senza inserire la password su openSSH