
我已經使用以下命令在 Ubuntu 14.04 系統中產生了金鑰以與 ssh 一起使用。
ssh-keygen -t rsa -b 2048
openssl rsa -in id_rsa -outform pem > pk_rsa.pem
openssl rsa -in pk_rsa.pem -pubout -out my_key.pem
我已將 my_key.pem 複製到本地 OSX。嘗試使用以下命令 ssh 進入 Ubuntu
ssh -v -i ./my_key.pem [email protected]
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 192.168.113.137 [192.168.113.137] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file ./ubu14.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file ./ubu14.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to 192.168.113.137:22 as 'ubuntu'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:KDokJiZiQ9ZflT5Jm5B8krQ8XgsEEgUjQjg+h6C4Gqo
debug1: Host '192.168.113.137' is known and matches the ECDSA host key.
debug1: Found key in /Users/macdev/.ssh/known_hosts:11
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: ./my_key.pem
Enter passphrase for key './my_key.pem':
debug1: Next authentication method: password
[email protected]'s password:
有辦法解決這個問題嗎?
答案1
您正在混淆兩種不同的技術,openssh
並且openssl
。看來您只需要前者。
由於您已經建立了 ssh 金鑰對,因此只需將公鑰複製到您想要 ssh 的伺服器即可。正確的方法是:
$ ssh-copy-id username@<server-ip>
代替使用者名稱和 <伺服器IP> 使用您的伺服器的使用者和 IP 位址。