CentOS 5 poskytuje skript s názvom ssh-copy-id
. Pomocou tohto skriptu dokážete automaticky nainštalovať súbor s ssh identity key na vzdialený počítač automaticky. Nasleduje príklad použitia tohto skriptu.
Najprv vygenerujeme lokálne autentikačné kľúče pomocou príkazu ssh-keygen
[user@server ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
86:43:4b:d1:50:ab:27:ee:50:b5:61:61:bf:c6:8c:9e user@server
Spustíme skript ssh-copy-id
a nainštalujeme verejný kľúč na vzdialeného hostiteľa
[user@server ~]$ ssh-copy-id -i .ssh/id_rsa.pub user@remote-host
user@remote-host's password:
Now try logging into the machine, with "ssh 'user@remote-host'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
Musíte zadať heslo pre prístup na vzdialený počítač a následne skript vloží na vzdialenom počítači informáciu o identite do súboru .ssh/authorized_keys
. Pokiaľ takýto súbor neexistuje, skript ho vygeneruje.