我一直在嘗試透過 SSH 驗證從 OS X 登入在 Azure 中執行 Ubuntu 的 VM。但是,當我嘗試連接到虛擬機器時,出現“權限被拒絕(公鑰)”錯誤。
為了建立密鑰對證書,我使用以下步驟透過終端機完成了操作:
openssl req -x509 -nodes -days 365 \
-newkey rsa:2048 \
-keyout example1.key \
-out example1.pem
然後我設定權限:
chmod 600 example1.key
這兩個文件都在我的用戶資料夾中。
在建立 VM 期間,我上傳了檔案 example1.pem。
建立虛擬機器後,我嘗試使用以下命令進行連線:
ssh -v -i myPrivateKey.key -p 22 [email protected]
這是我得到的輸出:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to ubuntuedx.cloudapp.net [23.99.90.218] port 22.
debug1: Connection established.
debug1: identity file myPrivateKey.key type -1
debug1: identity file myPrivateKey.key-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.4
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.4 pat OpenSSH_5*
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: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 20:b6:58:2c:96:75:f8:f6:b0:25:39:85:ed:ab:7a:9d
debug1: Host 'ubuntuedx.cloudapp.net' is known and matches the RSA host key.
debug1: Found key in /Users/juanse/.ssh/known_hosts:4
debug1: ssh_rsa_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
debug1: Next authentication method: publickey
debug1: Trying private key: myPrivateKey.key
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
我嘗試使用 VIP 而不是 VM 名稱,但得到相同的輸出。我在互聯網上查找了這裡發生的事情的答案,但我沒有找到解決我的問題的方法。
答案1
我不得不問,因為沒有說明。有一個步驟是您上傳 example1.pem,然後在安裝過程中將其儲存在使用者的 ~/.ssh/authorized_keys 檔案中。