
我正在學習 Hadoop 並嘗試按照書中定義的過程創建無密碼 SSH:Hadoop:權威指南
設定SSH
偽分散式模式只是完全分散式模式的一種特殊情況,其中(單一)主機是 localhost,因此我們需要確保可以透過 SSH 連接到 localhost 並無需輸入密碼即可登入。
首先,請確保已安裝 SSH 並且伺服器正在運行(我不確定這是什麼意思)。例如,在 Ubuntu 上,這是透過以下方式實現的:
sudo apt-get install ssh
然後,若要啟用無密碼登錄,請使用空密碼產生新的 SSH 金鑰:
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
您可能還需要運行ssh-添加如果您正在運行 ssh-agent.Test 您可以連線:
ssh localhost
如果成功,您不必輸入密碼。
一切似乎工作正常,但它仍然要求輸入密碼。我給了我的登入密碼,我也用它來進行 Root 存取。但它根本不起作用。請建議。
添加更多資訊。我刪除了舊密鑰並添加了新密鑰。
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
此後我的檔案權限是
-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
更改Authorized_key的權限後是
-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
但即使在此之後,當我這樣做時它也會要求我輸入密碼ssh localhost
ssh -v localhost
添加@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 [email protected] none debug1: kex: client->server aes128-ctr [email protected] 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:以下是輸出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:
答案1
該問題是由於檔案的權限造成的~/.ssh/authorized_keys
。它的權限不應該是其他人可以寫入該檔案。
例如,如果權限設定為八進位666
(確實是魔鬼!!),因為您可以讓所有其他人都擁有該檔案的寫入權限~/.ssh/authorized_keys
,那麼該檔案將被忽略,ssh
並會提示您輸入密碼。
假設該文件~/.ssh/authorized_keys
事先不存在,則以下命令
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
~/.ssh/authorized_keys
將使用您的值確定的權限建立文件umask
,然後附加文件的內容~/.ssh/id_rsa.pub
。
因此,解決方案是更改檔案的權限,使其只能由您寫入,例如:
chmod 600 ~/.ssh/authorized_keys