用户1需要能够su用户2在主机1,然后 ssh 到主机2使用公钥认证。密钥位于/home/user2/.ssh/id_rsa
host1 上。它适用于sudo -s
...
[user1@host1] $ sudo -u user2 -s
[user2@host1] $ ssh host2
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-70-generic x86_64)
...
Last login: ...
[user2@host2] $
但这不起作用...
[user1@host1] $ sudo -u user2 ssh host2
load pubkey "/home/user2/.ssh/id_rsa": Permission denied
load pubkey "/home/user2/.ssh/id_rsa": Permission denied
load pubkey "/home/user2/.ssh/id_dsa": Permission denied
load pubkey "/home/user2/.ssh/id_dsa": Permission denied
load pubkey "/home/user2/.ssh/id_ecdsa": Permission denied
load pubkey "/home/user2/.ssh/id_ecdsa": Permission denied
load pubkey "/home/user2/.ssh/id_ecdsa_sk": Permission denied
load pubkey "/home/user2/.ssh/id_ecdsa_sk": Permission denied
load pubkey "/home/user2/.ssh/id_ed25529": Permission denied
load pubkey "/home/user2/.ssh/id_ed25529": Permission denied
load pubkey "/home/user2/.ssh/id_ed25529_sk": Permission denied
load pubkey "/home/user2/.ssh/id_ed25529_sk": Permission denied
load pubkey "/home/user2/.ssh/id_xmss": Permission denied
load pubkey "/home/user2/.ssh/id_xmss": Permission denied
user2@host2's password:
问题是,为什么?
答案1
当我将 ssh 密钥从外部驱动器复制到新机器时,我遇到了同样的问题。
chmod 600 ~/.ssh/*
chmod u=rw,go= ~/.ssh/*
chmod 644 ~/.ssh/id_rsa.pub
chmod 700 ~/.ssh