ssh-add 适用于 id_ed25519 密钥,但不适用于 id_rsa 密钥

ssh-add 适用于 id_ed25519 密钥,但不适用于 id_rsa 密钥

我的文件夹中有两个密钥.ssh,一个是id_ed25519密钥,另一个是id_rsa密钥。如果我运行:

ssh-add ir_ed25519

我收到“已添加身份...”消息,一切正常。另一方面,如果我尝试ssh-add id_rsa,它会要求输入密码,我按回车键,因为我没有密码(本地项目),它会返回提示符。然后服务器拒绝了我(public key) error

编辑:

user@machine:~/.ssh$ ls
authorized_keys  config  google_compute_engine  google_compute_engine.pub  google_compute_known_hosts  id_ed25519  id_ed25519.pub  id_rsa  id_rsa.pub  known_hosts
user@machine:~/.ssh$ ssh-add id_ed25519
Identity added: id_ed25519 (my_gitlab_key)
user@machine:~/.ssh$ ssh-add id_rsa
Enter passphrase for id_rsa: 
user@machine:~/.ssh$ 


user@machine:~/.ssh$ ssh -p 27 user@server_URL.com
Enter passphrase for key '/home/user/.ssh/id_rsa': 
user@server_URL.com: Permission denied (publickey).

密钥id_rsa属于服务器。

编辑2:

user@computer:~/.ssh$ ssh -p 27 [email protected] -v 
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /home/user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to server-URL.com [xxxxxxxxxx] port 27.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519 type 3
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: identity file /home/user/.ssh/google_compute_engine type 0
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/google_compute_engine-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4p1 Debian-10+deb9u6
debug1: match: OpenSSH_7.4p1 Debian-10+deb9u6 pat OpenSSH* compat 0x04000000
debug1: Authenticating to server-URL.com:27 as 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
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:WCIqCPH...5A3dmWlf01g0m6k
debug1: Host '[server-URL.com]:27' is known and matches the ECDSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:1
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_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: ED25519 SHA256:HhRHqmr47/f0Lw+U3a+/a85ydnFvbns3KiQhKZbQC1Y /home/user/.ssh/id_ed25519
debug1: Authentications that can continue: publickey
debug1: Offering public key: RSA SHA256:D+NWN6yffzHS...s6JiUWVjEU /home/user/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
Enter passphrase for key '/home/user/.ssh/id_rsa': 
debug1: Offering public key: RSA SHA256:iUFi29EEETE...Sv1Q6dhypY2o /home/user/.ssh/google_compute_engine
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).

答案1

除非“id_rsa”已加密,否则它不会要求“输入密钥密码”。它有一个密码……不要只是按回车键。

您可以使用以下ssh-keygen命令验证这一点。例如,要更改密码,请使用以下命令:

ssh-keygen -p -f ~/.ssh/filenamehere

如果已有密码,它将要求输入旧密码,输入后,将要求输入新密码:

$ ssh-keygen -p -f ~/.ssh/filenamehere
Enter old passphrase: 
Key has comment 'examplecomment'
Enter new passphrase (empty for no passphrase): 

如果没有,它只会要求新的:

$ ssh-keygen -p -~/.ssh/filenamehere
Key has comment 'examplecomment'
Enter new passphrase (empty for no passphrase): 

相关内容