Kita mungkin menginginkan akses SSH secara langsung ke remote server tanpa login. Kita dapat menggunakan SSH Key untuk melakukan otentikasi.
Prinsip penggunaan SSH untuk otentikasi adalah
- Pada lokal membuat private_key dan public_key
- Kunci public_key dicopy ke remote
- Lokal dapat melakukan akses ke remote tanpa username dan password
Berikut contoh penggunaan
- Membuat private_key dan remote_key pada lokal:
[ultima@server-1041211-1 ~]$ ls .ssh known_hosts [ultima@server-1041211-1 ~]$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/ultima/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/ultima/.ssh/id_rsa. Your public key has been saved in /home/ultima/.ssh/id_rsa.pub. The key fingerprint is:
- Mencopy public_key ke remote server menggunakan perintah ssh-copy-id:
[ultima@server-1041211-1 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub backup@b1.adadeh.com The authenticity of host 'b1.adadeh.com (103.52.)' can't be established. ECDSA key fingerprint is d8:47:32:98:c8:f. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys backup@b1.adadeh.com's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'backup@b1.adadeh.com'" and check to make sure that only the key(s) you wanted were added.
Variasi jika menggunakan port adalah
ssh-copy-id -i ~/.ssh/id_rsa.pub backup@server2.adadeh.id -p 1530
- Langsung akses ssh:
[ultima@server-1041211-1 ~]$ ssh backup@b1.adadeh.com Last login: Thu Oct 15 15:45:46 2020 [backup@b1 ~]$
Pada remote akan muncul authorized_keys seperti berikut ini
[backup@b1 ~]$ ls -al .ssh total 16 drwx------. 2 backup backup 80 Oct 15 16:03 . drwx------. 3 backup backup 95 Oct 15 15:43 .. -rw-------. 1 backup backup 423 Oct 15 16:03 authorized_keys
Untuk menggunakan rsync kita dapat menjalankan perintah seperti berikut ini
rsync -ar ./client backup@b1.adadeh.com:ultima2
Untuk menggunakan rsync pada port selain 22 kita dapat menggunakan perintah seperti berikut ini
rsync -ar /backup backup@b1.adadeh.com:sg4 --rsh='ssh -p 1530'
Informasi lebih lanjut silahkan mengunjung
1. https://upcloud.com/community/tutorials/use-ssh-keys-authentication/ .
2. https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories-on-a-vps .
3. https://www.linuxquestions.org/questions/linux-software-2/rsync-ssh-on-different-port-448112/ .
4. https://www.tecmint.com/rsync-local-remote-file-synchronization-commands/ .
5. https://www.proweb.co.id/articles/centos7/screen_ssh.html .
Kunjungi www.proweb.co.id untuk menambah wawasan anda.