我在 Windows 10 上使用 OpenSSH 客户端连接到 Debian 服务器。
我的所有密钥都存储在C:\Users\entityinarray\.ssh\
PS C:\Users\entityinarray> ssh [email protected]
[email protected]: Permission denied (publickey).
PS C:\Users\entityinarray> ssh [email protected] -o IdentityFile=~\.ssh\id_okcomputer
Enter passphrase for key 'C:\Users\entityinarray/\.ssh\id_okcomputer':
Linux okserver 6.1.0-17-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.69-1 (2023-12-30) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Feb 7 09:55:39 2024 from 192.168.1.2
root@okserver:~#
传递IdentityFile=~\.ssh\id_okcomputer
有效!但我希望它能自动找到密钥。
我的~\.ssh\config
:
Host example.com
HostName example.com
Port 22
IdentityFile ~/.ssh/id_okcomputer
Host radio.example.com
HostName radio.example.com
Port 2022
IdentityFile ~/.ssh/id_okcomputer
Host linux-gaming
HostName 123.123.123.123
Port 22
IdentityFile ~/.ssh/id_okcomputer
答案1
您指定了192.168.1.100
SSH 主机名,但 ~/.ssh/config 中没有此Host 192.168.1.100
部分。其中仅有的部分针对的是完全不同的主机。
如果您想要一个适用IdentityFile
于所有主机的参数,请将其放在一个Host *
部分中(应该在末尾,在更具体的匹配之下)。