Ubuntu – Hadoop in Ubuntu : Unable to create Passwordless SSH

hadooppasswordssh

I am learning Hadoop and trying to create the passwordless SSH following the procedure in define in the Book : Hadoop: The Definitive guide

Configuring SSH

Pseudodistributed mode is just a special case of fully distributed mode in which
the (single) host is localhost, so we need to make sure that we can SSH to localhost and
log in without having to enter a password.

First, make sure that SSH is installed and a server is running (I
am not sure about this,What they mean). On Ubuntu, for example,
this is achieved with:

sudo  apt-get install ssh

Then, to enable passwordless login, generate a new SSH key with an empty passphrase:

  ssh-keygen  -t  rsa -P  ''  -f  ~/.ssh/id_rsa
  cat ~/.ssh/id_rsa.pub   >>  ~/.ssh/authorized_keys

You may also need to run ssh-add if you are running ssh-agent.Test that you can connect with:

  ssh localhost

If successful, you should not have to type in a password.

Everything seems working fine, but it still ask for Password. I am giving my login password, which I also use for Root access. but It doesn't work at all. Please suggest.

Adding more information. I deleted old key and added new.

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

My file permissions after this were

-rw-rw-r-- 1 incredible incredible  403 मई    24 17:16 authorized_keys
-rw------- 1 incredible incredible 1679 मई    23 23:08 id_rsa
-rw-r--r-- 1 incredible incredible  403 मई    23 23:08 id_rsa.pub
-rw-r--r-- 1 incredible incredible  444 मई    24 17:12 known_hosts

after changing the permission of Authorized_key it is

-rw------- 1 incredible incredible  403 मई    24 17:16 authorized_keys
-rw------- 1 incredible incredible 1679 मई    23 23:08 id_rsa
-rw-r--r-- 1 incredible incredible  403 मई    23 23:08 id_rsa.pub
-rw-r--r-- 1 incredible incredible  444 मई    24 17:12 known_hosts

But even after this, it is asking me for password when I do ssh localhost

Adding more info output of ssh -v localhost asked by @heemayl

incredible@incredible:~$ ssh -v localhost
OpenSSH_6.7p1 Ubuntu-5ubuntu1, 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 localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /home/incredible/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/incredible/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/incredible/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/incredible/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/incredible/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/incredible/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/incredible/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/incredible/.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-5ubuntu1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.7p1 Ubuntu-5ubuntu1
debug1: match: OpenSSH_6.7p1 Ubuntu-5ubuntu1 pat OpenSSH* 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 3c:e1:36:10:30:19:b3:e1:43:73:a5:6c:76:9e:24:67
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /home/incredible/.ssh/known_hosts:1
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,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/incredible/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /home/incredible/.ssh/id_dsa
debug1: Trying private key: /home/incredible/.ssh/id_ecdsa
debug1: Trying private key: /home/incredible/.ssh/id_ed25519
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
incredible@localhost's password:

@heemayl : Following is the output of ssh -vvv localhost

debug1: Offering RSA public key: /home/incredible/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Offering RSA public key: incredible@incredible
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /home/incredible/.ssh/id_dsa
debug3: no such identity: /home/incredible/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/incredible/.ssh/id_ecdsa
debug3: no such identity: /home/incredible/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/incredible/.ssh/id_ed25519
debug3: no such identity: /home/incredible/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup keyboard-interactive
debug3: remaining preferred: password
debug3: authmethod_is_enabled keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug3: userauth_kbdint: disable: no info_req_seen
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred:
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
incredible@localhost's password:

Best Answer

  • The issue is due to the permission of the ~/.ssh/authorized_keys file. Its permission should not be such that others can write into the file.

    For example, if the permission is set as octal 666 (it is devil indeed !!), as you can all others have the write permission in the file ~/.ssh/authorized_keys, then the file will be ignored by ssh and you will prompted for the password.

    Assuming the file ~/.ssh/authorized_keys does not exists beforehand, the following command

    cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
    

    will create the file ~/.ssh/authorized_keys with the permission determined by your umask value and then append the content of the ~/.ssh/id_rsa.pub file.

    So, the solution is to change the permission of the file so that it is only writable by you, for example:

    chmod 600 ~/.ssh/authorized_keys