Posting menguraikan langkah-langkah untuk mengonfigurasi ssh tanpa kata sandi antara 2 host CentOS/RHEL. Langkah-langkahnya tetap hampir sama dengan sedikit perubahan di semua distribusi Linux.
1. Masuk sebagai pengguna yang ingin Anda atur kunci ssh, dalam hal ini, kami menggunakan pengguna “geek”.
2. Buat kunci pribadi dan publik :
$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/geek/.ssh/id_rsa): Created directory '/home/geek/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/geek/.ssh/id_rsa. Your public key has been saved in /home/geek/.ssh/id_rsa.pub. The key fingerprint is: SHA256:joc/+DIFmDiSD9qc/ZuF5I/iA1ghBK+f3niOnbfYFrk geek@node01 The key's randomart image is: +---[RSA 2048]----+ |+. | |... | | o.o o | |+.+ o . | |oO + .oS | |o.*..oo=. | | o. .==+ | | . =++EB. | | ++B=**+. | +----[SHA256]-----+
Catatan:
Anda dapat menentukan opsi pada ssh-keygen seperti ukuran dan jenisnya. Informasi lebih lanjut tentang man ssh-keygen
-b bit
Menentukan jumlah bit dalam kunci yang akan dibuat. Untuk kunci RSA, ukuran minimumnya adalah 768 bit dan standarnya adalah 2048 bit. Umumnya, 2048 bit dianggap cukup. Kunci DSA harus tepat 1024 bit seperti yang ditentukan oleh FIPS 186-2.
-t jenis
Menentukan jenis kunci yang akan dibuat. Nilai yang mungkin adalah “rsa1” untuk protokol versi 1 dan “dsa”, “ecdsa” atau “rsa” untuk protokol versi 2.
3. Kunci Baru akan ditempatkan di /home/geek/.ssh . Pindah ke direktori .ssh tempat kunci dibuat dan verifikasi:
$ cd .ssh $ ls id_rsa id_rsa.pub
4. Salin kunci publik ke server target (node02)
$[geek@node01 .ssh]$ ssh-copy-id -i id_rsa.pub geek@node02 /bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.pub" The authenticity of host 'node02 (192.168.1.12)' can't be established. ECDSA key fingerprint is SHA256:PJplQZl2GQqpoJDK7d4nubIP65/A6YyKBGSSaObvzXo. ECDSA key fingerprint is MD5:a1:53:e6:d8:9a:71:47:ba:86:a1:d5:d2:25:4c:7c:3b. Are you sure you want to continue connecting (yes/no)? yes /bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.pub" /bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys geek@node02's password: Number of key(s) added: 1 Now try logging into the machine, with "ssh 'geek@node02'" and check to make sure that only the key(s) you wanted were added.
5. Sekarang uji kunci Anda, Anda harus login langsung ke server target.
[geek@node01 .ssh]$ ssh geek@node02 [geek@node02 ~]$
Catatan:jika server Anda belum menginstal paket openssh-clients, alternatif lain adalah :
$ cat id_rsa.pub | ssh user@node02 "cat >> ~/.ssh/authorized_keys"