GNU/Linux >> Linux Esercitazione >  >> Linux

Come configurare le chiavi SSH per l'accesso ssh "senza password" in Linux

Il post elenca i passaggi per configurare le chiavi ssh per configurare ssh senza password in Linux. ssh-keygen è il comando utilizzato per generare le chiavi pubbliche e private se non l'hai già fatto. Con il comando ssh-copy-id, possiamo copiare le chiavi sul server di destinazione su cui vogliamo avere una configurazione ssh senza password.

1. Accedi come utente per il quale desideri configurare le chiavi ssh. In questo caso, stiamo usando l'utente sand.

2. Creare una chiave privata e pubblica per l'utente sand. Premi Invio due volte quando viene richiesta la passphrase poiché manterremo la passphrase vuota.

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/sandy/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/sandy/.ssh/id_rsa.
Your public key has been saved in /Users/sandy/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Y2lfHXY1+i5Pok1NuhsfZ16JsIrdUzY1699SwlvOHOY [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|               ..|
|              . o|
|             .o .|
|         .   o.= |
|        S  ...ooo|
|       o o .o+O++|
|          ..oB=#=|
|        o o.+ @EO|
|       . o o.+.+=|
+----[SHA256]-----+
Nota :puoi specificare un'opzione su ssh-keygen come la dimensione e il tipo . Puoi trovare maggiori informazioni sulla pagina man del comando ssh-keygen

Dalla pagina man di ssh-keygen :

-b bits

Specifies the number of bits in the key to create. For RSA keys, the minimum size is 768 bits and the default is 2048 bits. Generally, 2048 bits is considered sufficient. DSA keys must be exactly 1024 bits as specified by FIPS186-2.

-t type

Specifies the type of key to create. The possible values are “rsa1” for protocol version 1 and “dsa”, “ecdsa” or “rsa” for protocol version 2.

3. Le nuove chiavi si troveranno in /home/test1/.ssh. Passa alla tua directory .ssh in cui è stata creata la chiave controlla per il pubblico

$ cd .ssh
$ $ ls -lrt id*
-rw-r--r--  1 sandy  staff   414 Oct 20 20:35 id_rsa.pub
-rw-------  1 sandy  staff  1675 Oct 20 20:35 id_rsa

4.Copiare la chiave pubblica sul server di destinazione.

$ ssh-copy-id -i id_rsa.pub test1@lab02
The authenticity of host 'lab02 (192.168.219.149)' can't be established.
RSA key fingerprint is dd:0c:77:26:da:f4:ed:30:64:26:96:29:b3:38:cc:9c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'lab02,192.168.219.149' (RSA) to the list of known hosts.
test1@lab02's password:

Verifica

1. Ora prova ad accedere alla macchina, con “ssh ‘test1@lab02′”, e controlla il file ~/.ssh/authorized_keys per assicurarci che non abbiamo aggiunto chiavi extra che non ti aspettavi.

2. Verifica la tua chiave, dovresti accedere direttamente al tuo server di destinazione senza che venga richiesta una password.

$ ssh test1@lab02
[test1@lab02 ~]$

metodo alternativo se il comando ssh-copy-id non è disponibile

Se il tuo server non ha i openssh-clients pacchetto installato, è possibile utilizzare un metodo alternativo. Puoi copiare direttamente la chiave pubblica usando il comando scp.

$ cat id_rsa.pub | ssh user@lab02 "cat >> ~/.ssh/authorized_keys"


Linux
  1. Come configurare l'accesso SSH senza password

  2. Come impostare le chiavi SSH

  3. Come convertire il file PPK in chiavi OpenSSH e accedere utilizzando SSH in Linux?

  4. Come configurare l'accesso SSH senza password in Linux

  5. Come configurare le chiavi SSH per l'accesso SSH "senza password" su CentOS/RHEL

Come configurare l'accesso senza password SSH in Rocky Linux

Come configurare l'accesso senza password SSH in AlmaLinux

Configura l'accesso SSH senza password per più server remoti utilizzando lo script

Come configurare le chiavi SSH su Debian 11 Linux

Genera chiavi SSH per l'accesso senza password in Ubuntu

Come disabilitare l'accesso SSH per l'utente root in Linux?