ssh “id_rsa 、id_rsa.pub、known_hosts”替换中出现的问题

本文介绍如何正确配置SSH密钥并解决权限问题。包括将密钥放置于指定目录、使用keychain命令进行评估及调整文件权限等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【1】将已有的key放在你home目录的.ssh里面 
        keychain --eval ~/.ssh/id_rsa   运行这个命令
        eval `keychain --eval ~/.ssh/id_rsa`   输入后,需要输入一个密码  rd

【2】之前替换了一次id_rsa 、id_rsa.pub、known_hosts,然后再去git clone的时候就会出现输入密码有误;替换成备份的id_rsa 、id_rsa.pub、known_hosts之后 出现以下错误:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @  
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  
Permissions 0644 for '/home/robin/.ssh/id_rsa' are too open.  
It is recommended that your private key files are NOT accessible by others.  
This private key will be ignored.  
bad permissions: ignore key: /home/rd4/.ssh/id_rsa 

上面的问题就是这三个文件的权限不对!
解决方案 :
chmod 755 ~/.ssh/  
chmod 600 ~/.ssh/id_rsa ~/.ssh/id_rsa.pub   
chmod 644 ~/.ssh/known_hosts 

【3】之后需要输入命令:eval `keychain --eval ~/.ssh/id_rsa`   回车后,需要输入一个密码   这样就可以了

下面是我在客户端尝试使用ssh密钥对登录的详细调试日志,请你发现其中的错误,给出解决的方法: C:\Users\86196>ssh -i C:\\Users\\86196\\.ssh\\id_rsa -vvv lyq@192.168.25.100 OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2 debug3: Failed to open file:C:/Users/86196/.ssh/config error:2 debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2 debug2: resolve_canonicalize: hostname 192.168.25.100 is address debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> 'C:\\Users\\86196/.ssh/known_hosts' debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> 'C:\\Users\\86196/.ssh/known_hosts2' debug3: ssh_connect_direct: entering debug1: Connecting to 192.168.25.100 [192.168.25.100] port 22. debug1: Connection established. debug1: identity file C:\\\\Users\\\\86196\\\\.ssh\\\\id_rsa type 0 debug3: Failed to open file:C:/Users/86196/.ssh/id_rsa-cert error:2 debug3: Failed to open file:C:/Users/86196/.ssh/id_rsa-cert.pub error:2 debug3: failed to open file:C:/Users/86196/.ssh/id_rsa-cert error:2 debug1: identity file C:\\\\Users\\\\86196\\\\.ssh\\\\id_rsa-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_for_Windows_9.5 debug1: Remote protocol version 2.0, remote software version OpenSSH_8.9p1 Ubuntu-3ubuntu0.11 debug1: compat_banner: match: OpenSSH_8.9p1 Ubuntu-3ubuntu0.11 pat OpenSSH* compat 0x04000000 debug2: fd 3 setting O_NONBLOCK debug1: Authenticating to 192.168.25.100:22 as 'lyq' debug3: record_hostkey: found key type ED25519 in file C:\\Users\\86196/.ssh/known_hosts:2 debug3: record_hostkey: found key type RSA in file C:\\Users\\86196/.ssh/known_hosts:3 debug3: record_hostkey: found key type ECDSA in file C:\\Users\\86196/.ssh/known_hosts:4 debug3: load_hostkeys_file: loaded 3 keys from 192.168.25.100 debug3: Failed to open file:C:/Users/86196/.ssh/known_hosts2 error:2 debug1: load_hostkeys: fopen C:\\Users\\86196/.ssh/known_hosts2: No such file or directory debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2 debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts: No
03-08
git@github.com$ ssh -T -vvv git@github.com OpenSSH_9.9p1, OpenSSL 3.2.4 11 Feb 2025 debug1: Reading configuration data /c/Users/SW0122/.ssh/config debug1: Reading configuration data /etc/ssh/ssh_config debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/SW0122/.ssh/known_hosts' debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/SW0122/.ssh/known_hosts2' debug2: resolving "github.com" port 22 debug3: resolve_host: lookup github.com:22 debug3: channel_clear_timeouts: clearing debug3: ssh_connect_direct: entering debug1: Connecting to github.com [20.205.243.166] port 22. debug3: set_sock_tos: set socket 4 IP_TOS 0x48 debug1: Connection established. debug1: identity file /c/Users/SW0122/.ssh/id_rsa type 0 debug1: identity file /c/Users/SW0122/.ssh/id_rsa-cert type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ecdsa type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ecdsa-cert type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ecdsa_sk type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ecdsa_sk-cert type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ed25519 type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ed25519-cert type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ed25519_sk type -1 debug1: identity file /c/Users/SW0122/.ssh/id_ed25519_sk-cert type -1 debug1: identity file /c/Users/SW0122/.ssh/id_xmss type -1 debug1: identity file /c/Users/SW0122/.ssh/id_xmss-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_9.9 debug1: Remote protocol version 2.0, remote software version 6fdec156f debug1: compat_banner: no match: 6fdec156f debug2: fd 4 setting O_NONBLOCK debug1: Authenticating to github.com:22 as 'git' debug3: record_hostkey: found key type ED25519 in file /c/Users/SW0122/.ssh/known_hosts:1 debug3: load_hostkeys_file: loaded 1 keys from github.com debug1: load_hostkeys: fopen /c/Users/SW0122/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /e: Permission denied (publickey).
04-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值