使用 SSH 公鑰登入不起作用

使用 SSH 公鑰登入不起作用

所以我有我的家用電腦和我的伺服器。我正在嘗試使用我的私鑰登入我的伺服器。

在我的伺服器上說我有用戶serveruser,我使用它從我的家庭電腦登入

ssh -Y [email protected]

homeuser在我的家用電腦上,我的家用電腦上有該使用者。

所以現在,我想使用我的私鑰登入伺服器。為此,我已經有一個帶有密碼的密鑰/home/homeuser/.ssh/。因此,我取得了公鑰 (id_rsa.pub),並將其複製到我的伺服器(位於 )/home/serveruser/.ssh/authorized_keys

現在我想使用該密鑰登錄,所以我嘗試使用

ssh -Y [email protected]

它仍然要求我輸入密碼,而不是密碼短語。

我也嘗試使用登入

ssh -i /home/homeuser/.ssh/id_rsa -Y [email protected]

並且仍然要求我提供用戶密碼。

我做錯了什麼?請指教。

感謝您所做的一切努力。

編輯:根據 Mason Heller 的建議,我執行了 ssh-add,但它仍然堅持要求我輸入密碼[電子郵件受保護]

編輯:來自ssh -v -Y myserver.com(為匿名而修改的個人資訊)的資訊。

OpenSSH_5.9p1 Debian-5ubuntu1.1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to myserver.com [100.100.100.100] port 22.
debug1: Connection established.
debug1: identity file /home/homeuser/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/homeuser/.ssh/id_rsa-cert type -1
debug1: identity file /home/homeuser/.ssh/id_dsa type -1
debug1: identity file /home/homeuser/.ssh/id_dsa-cert type -1
debug1: identity file /home/homeuser/.ssh/id_ecdsa type -1
debug1: identity file /home/homeuser/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-4
debug1: match: OpenSSH_6.0p1 Debian-4 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA b2:1a:68:21:5a:72:c4:f7:ec:ea:60:12:e4:f8:b5:71
debug1: Host 'myserver.com' is known and matches the ECDSA host key.
debug1: Found key in /home/homeuser/.ssh/known_hosts:11
debug1: ssh_ecdsa_verify: signature correct
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/homeuser/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: [email protected]
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/homeuser/.ssh/id_dsa
debug1: Trying private key: /home/homeuser/.ssh/id_ecdsa
debug1: Next authentication method: password

更多資訊:

貓 /home/homeuser/.ssh/id_rsa.pub

--removed for security--

/home/serveruser/.ssh/authorized_keys

total 4
-rwx------ 1 serveruser serveruser 400 Jan 26 01:09 id_rsa.pub

貓 /home/serveruser/.ssh/authorized_keys

cat: /home/serveruser/.ssh/authorized_keys: Is a directory

答案1

/home/serveruser/.ssh/authorized_keys應該是一個文件。

您可以透過新增 id_rsa.pub 的內容來建立它(即 cat /home/homeuser/.ssh/id_rsa.pub >>authorized_keys)。

(顯然你必須先將公鑰複製到伺服器。)

答案2

為了使用您的金鑰對,您可能需要執行 ssh-agent 來處理身份驗證。

eval $(ssh-agent)
ssh-add

然後您的金鑰對將可用於該終端機中的所有後續 ssh 工作階段。ssh-agent在終端會話中新增環境變量,您需要ssh使用它。我通常ssh-agent > ~/.ssha; . ~/.ssha; ssh-add在一個 pty 中運行,然後source ~/.ssha在需要使用 ssh 的任何其他 pty 中運行,以便我的所有 pty 都可以使用該代理。此外,我發現將我的公鑰添加到伺服器

更容易。ssh-copy-id它也可能讓你的生活更輕鬆。 :)

相關內容