Koneksi remote server dengan SSH tanpa password

Banyak fungsi yang dapat digunakan menggunakan SSH, seperti :
  1. Remote control server
  2. Secure Copy (SCP)
  3. Secute FTP (SFTP)
Fungsi-fungsi tersebut diatas akan selalu ditanyakan password untuk proses autentifikasi.
 
Dalam proses otomatisasi seperti halnya backup file menggunakan scp, yang dilakukan menggunakan fasilitas cronjob (pekerjaan terjadwal), maka proses autentifikasi password akan menjadi kendala besar, karena harus menunggu user input password.
Untuk mempermudah hal tersebut, di Linux (Digunakan CENTOS disini) otentifikasi password dapat diubah dalam bentuk file-kunci.
File kunci harus dibuat di server remote, yaitu server yang akan dilakukan remote control.
Ada tiga jenis file kunci, yaitu :
  • rsa1
  • rsa
  • dsa
Urutan pembuatannya yaitu dengan cara :
  1. Asumsi user yang digunakan yaitu prayitna
  2. Di komputer remote, misalnya webserver
    1. Buat file-kunci, dengan cara
      # ssh-keygen -t rsa1
      atau
      # ssh-keygen -t rsa
      atau
      # ssh-keygen -t dsa
      setiap perintah akan diminta memasukkan password (passphrases), dimana antara ketiga perintah diatas bisa dibuat sama ataupun berbeda-beda.
      contoh :
      $ ssh-keygen -t rsa
      Generating public/private rsa key pair.
      Enter file in which to save the key (/home/prayitna/.ssh/id_rsa):
      Enter passphrase (empty for no passphrase):
      Enter same passphrase again:
      Your identification has been saved in /home/prayitna/.ssh/id_rsa.
      Your public key has been saved in /home/prayitna/.ssh/id_rsa.pub.
      The key fingerprint is:
      80:04:2e:04:c1:8c:d8:2a:a5:4e:46:1b:dd:fe:09:bc prayitna@webserver
      The key’s randomart image is:
      +–[ RSA 2048]—-+
      |O+o.o            |
      |+*oo o           |
      |o++ + .          |
      |+=   + .         |
      |=     + S        |
      | .   E o         |
      |                 |
      |                 |
      |                 |
      +—————–+
    2. Dari perintah diatas akan dihasilkan tiga pasang file-kunci, yaitu :
      identity        identity.pub
      id_dsa          id_dsa.pub
      id_rsa          id_rsa.pub
  3. Di komputer lokal, misalnya backupserver
    1. Cek  folder ~/.ssh ada atau belum, jika belum ada maka buat foldernya dahulu
      # cd ~
      # mkdir .ssh
      # chmod 700 .ssh
    2. Salin pasangan file-kunci dari remote server, misalnya id_rsa dan id_rsa.pub, ke lokal komputer di folder ~/.ssh
      # scp prayitna@webserver:~/.ssh/* ~/.ssh
    3. Otorisasi file-kunci ke remote server
      # ssh-copy-id -i ~/.ssh/id_rsa.pub prayitna@webserver
      21
      prayitna@webserver’s password:
      Now try logging into the machine, with “ssh ‘prayitna@webserver’”, and check in:
      .ssh/authorized_keys
      to make sure we haven’t added extra keys that you weren’t expecting.
    4. Proses diatas harus memasukkan password dan akan membuat / atau menambah isi file .ssh/authorized_keys di remote server
    5. Uji coba dengan SSH ke webserver user prayitna, maka mestinya tidak akan ditanyakan password user.
  4. Ketentuan lain-lain :
    1. SSH server di backupserver harus support otentifikasi menggunakan file-kunci, jika tidak support maka proses ini akan gagal.
      Cek configurasi ssh server, yaitu harus aktif untuk 2 baris berikut
      -   RSAAuthentication yes
      -   PubkeyAuthentication yes # vi /etc/ssh/ssh_config
      # $OpenBSD: ssh_config,v 1.21 2005/12/06 22:38:27 reyk Exp $
      # This is the ssh client system-wide configuration file. See
      # ssh_config(5) for more information. This file provides defaults for
      # users, and the values can be changed in per-user configuration files
      # or on the command line.
      # Configuration data is parsed as follows:
      # 1. command line options
      # 2. user-specific file
      # 3. system-wide file
      # Any configuration value is only changed the first time it is set.
      # Thus, host-specific definitions should be at the beginning of the
      # configuration file, and defaults at the end.
      # Site-wide defaults for some commonly used options. For a comprehensive
      # list of available options, their meanings and defaults, please see the
      # ssh_config(5) man page.
      # Host *
      # ForwardAgent no
      # ForwardX11 no
      # RhostsRSAAuthentication no
      # RSAAuthentication yes
      # PasswordAuthentication yes
      # HostbasedAuthentication no
      # BatchMode no
      # CheckHostIP yes
      # AddressFamily any
      # ConnectTimeout 0
      # StrictHostKeyChecking ask
      # IdentityFile ~/.ssh/identity
      # IdentityFile ~/.ssh/id_rsa
      # IdentityFile ~/.ssh/id_dsa
      # Port 22
      # Protocol 2,1
      # Cipher 3des
      # Ciphers aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc
      # EscapeChar ~
      # Tunnel no
      # TunnelDevice any:any
      # PermitLocalCommand no
      Host *
      GSSAPIAuthentication yes
      RSAAuthentication yes
      PubkeyAuthentication yes

      # If this option is set to yes then remote X11 clients will have full access
      # to the original X11 display. As virtually no X11 client supports the untrusted
      # mode correctly we set this to yes.
      ForwardX11Trusted yes
      # Send locale-related environment variables
      SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
      SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
      SendEnv LC_IDENTIFICATION LC_ALL
      Jika dilakukan perubahan konfigurasi ssh, maka perlu dilakukan restart ssh server
      # service sshd restart
    2. Passphrase saat membuat file-kunci di remote serverJika dikosongkan, maka saat melakukan ssh dari backupserver maka tidak akan ditanyakan password, akan tetapi jika diisi, maka saat melakukan ssh akan ditanyakan passphrase tersebut.
Semoga bermanfaat dan mempermudah

0 comments:

Post a Comment

Please Enable JavaScript!
Mohon Aktifkan Javascript![ Enable JavaScript ]
close
iklan 120 x 600 kanan
close