linux:debian:ssh-key-transfer
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:debian:ssh-key-transfer [2023/09/07 17:10] – [Key transfer - with ssh-copy-id] oscar | linux:debian:ssh-key-transfer [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Setup ssh-key exchange ====== | ||
| - | It is possible to automatically login in a ssh session on a remote system, without entering a password. Also copying files with scp without password is possible. To make this possible a public ssh key needs to be exchanged between the source and the target system. | ||
| - | On the source system an ssh key pair is generated. The public key is transferred to the target system and will be used to validate the login attempt that is signed with the private key. | ||
| - | ===== Source System Key pair Generation ==== | ||
| - | The next commands should be performed by the user that wants to ssh/scp to the target system. Steps below assume that this is the root user, but this could also be www-data, etc. | ||
| - | As user on the source system, use ssh-keygen to generate a public/ | ||
| - | < | ||
| - | # cd /root/.ssh | ||
| - | # ssh-keygen -t rsa -b 2048 | ||
| - | --------------------------------------------------- | ||
| - | # Generating public/ | ||
| - | Enter file in which to save the key (/ | ||
| - | Enter passphrase (empty for no passphrase): | ||
| - | Enter same passphrase again: | ||
| - | Your identification has been saved in / | ||
| - | Your public key has been saved in / | ||
| - | </ | ||
| - | |||
| - | ===== Public Key Exchange ===== | ||
| - | To allow the user on the source system to ssh to the target system, you need to place the users public key into authorized list of the user on the target system. There are 2 different ways to achieve this: | ||
| - | * Manual | ||
| - | * With ' | ||
| - | |||
| - | The public key of the user on the source system should be included into the **/ | ||
| - | ==== Key transfer - Manual ==== | ||
| - | Append the public key to root's / | ||
| - | # cd / | ||
| - | # scp user_target@192.168.xx.xx:/ | ||
| - | # touch ~/ | ||
| - | # cat client_id_rsa.pub >> ~/ | ||
| - | # rm client_id_rsa.pub | ||
| - | ==== Key transfer - with ssh-copy-id ==== | ||
| - | Copy your keys to the target system: | ||
| - | < | ||
| - | $ ssh-copy-id -i id_rsa.pub root@targetsystem | ||
| - | |||
| - | remoteusername@targetsystem' | ||
| - | </ | ||
| - | Now try logging into the machine, with ssh ' | ||
| - | < | ||
| - | / | ||
| - | or | ||
| - | / | ||
| - | </ | ||
| - | |||
| - | ==== Host Authenticity (Finger print) ==== | ||
| - | When you for the first time ssh/scp into a remote host, you will get the following question: | ||
| - | < | ||
| - | The authenticity of host ' | ||
| - | ED25519 key fingerprint is SHA256: | ||
| - | This key is not known by any other names. | ||
| - | Are you sure you want to continue connecting (yes/ | ||
| - | </ | ||
| - | When accepted this key is placed into the client' | ||
| - | |||
| - | Or you can place the target public key into the ~/ | ||
| - | < | ||
| - | $ scp root@192.168.xx.xx:/ | ||
| - | $ touch ~/ | ||
| - | $ cat ~/ | ||
| - | $ rm target-key.pub | ||
| - | </ | ||
| - | Or symply try to ssh from client to target as root. The key will be placed automatically in known_hosts file. | ||
| - | |||
| - | ==== On the Target System ==== | ||
| - | This might not be necessary if the client key has already be created for other targets, so you can reuse it. Repeat the above steps for the user ' | ||
| - | < | ||
| - | $ cd / | ||
| - | $ ssh-keygen -t rsa -b 2048 | ||
| - | --------------------------------------------------- | ||
| - | # Generating public/ | ||
| - | Enter file in which to save the key (/ | ||
| - | Enter passphrase (empty for no passphrase): | ||
| - | Enter same passphrase again: | ||
| - | Your identification has been saved in / | ||
| - | Your public key has been saved in / | ||
| - | </ | ||
| - | After this the file ~/ | ||
| - | Make a copy of the public key to make it recognizable. | ||
| - | |||
| - | ===== Test ===== | ||
| - | This should now work from the server to the client: | ||
| - | $ ssh root@192.168.xx.xx | ||
| - | If everything went ok, you should be logged in directly without a password prompt. | ||
linux/debian/ssh-key-transfer.1694106603.txt.gz · Last modified: by oscar
