21 Mei 2015 - 13:22:55 - Read: 997

Mengurangi Delay Autentikasi Login via SSH

Untuk beberapa system seperti CentOS, konfigurasi default untuk SSH biasanya mengaktifkan semua jenis authentikasi. Dengan mengaktifkan jalur-jalur authentikasi ini, akan memperlambat client melakukan koneksi via SSH. Karena jalur-jalur ini akan dicoba satu persatu.
jamz@jAcer:~$ ssh root@123.123.123.123 -p123 -v
OpenSSH_6.7p1 Ubuntu-3, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 123.123.123.123 [123.123.123.123] port 123.
debug1: Connection established.
debug1: identity file /home/jamz/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Ubuntu-3
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr umac-64-etm@openssh.com none
debug1: kex: client->server aes128-ctr umac-64-etm@openssh.com none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 4d:e9:8b:7d:05:98:03:4e:68:03:7d:50:cc:f4:ad:38
debug1: checking without port identifier
The authenticity of host '[118.97.31.181]:666 ([118.97.31.181]:666)' can't be established.
ECDSA key fingerprint is 4d:e9:8b:7d:05:98:03:4e:68:03:7d:50:cc:f4:ad:38.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[123.123.123.123]:123' (ECDSA) to the list of known hosts.
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available

debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/jamz/.ssh/id_rsa
Perhatikan pada baris
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
Autentikasi menggunakan password yang akan kita gunakan berada pada prioritas paling akhir. Sedangkan jalur autentikasi yang lain akan dicoba terlebih dahulu. Berikut ini salah satu tips untuk menutup service API untuk authentikasi SSH yang biasanya tidak digunakan, dengan menutup API GSS. Edit file di /etc/ssh/sshd_config lalu cari baris:
# GSSAPI options
GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
ganti "GSSAPIAuthentication no" menjadi "GSSAPIAuthentication yes" lalu restart sshd
#Debian
/etc/init.d/sshd restart

#Ubuntu terbaru
service sshd restart

#CentOS
systemctl restart sshd
Setelah ini, maka percobaan autentikasi dengan service API GSS akan dilewatkan.
jamz@jAcer:~$ ssh root@123.123.123.123 -p123 -v
OpenSSH_6.7p1 Ubuntu-3, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 123.123.123.123 [123.123.123.123] port 123.
debug1: Connection established.
debug1: identity file /home/jamz/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/jamz/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Ubuntu-3
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr umac-64-etm@openssh.com none
debug1: kex: client->server aes128-ctr umac-64-etm@openssh.com none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 4d:e9:8b:7d:05:98:03:4e:68:03:7d:50:cc:f4:ad:38
debug1: Host '[123.123.123.123]:123' is known and matches the ECDSA host key.
debug1: Found key in /home/jamz/.ssh/known_hosts:39
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/jamz/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: IT-RACE-2015
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/jamz/.ssh/id_dsa
debug1: Trying private key: /home/jamz/.ssh/id_ecdsa
debug1: Trying private key: /home/jamz/.ssh/id_ed25519
debug1: Next authentication method: password
root@123.123.123.123's password: 
Dengan melihat logs diatas, terlihat juga ketika kita ingin login menggunakan public_key, semua public_key yang tersimpan di client akan digunakan. Hal ini juga salah satu penyebab koneksi via SSH menjadi lambat. Jika kita menggunakan public_key sebagai metode autentikasi untuk login, langsung berikan public_key yang tepat untuk server yang akan kita buka,
jamz@jAcer:~$ ssh root@123.123.123.123 -p123 -i ~/.ssh/public_key
Yarp, semoga tips sederhana ini bermanfaat.