问题
我已经在本地计算机上创建了私钥和公钥,并将我的公钥复制到了linode 的authorized_keys文件中。但当我尝试ssh到linode时,我得到错误消息" Permission denied (publickey)。
在我本地ubuntu机器上的.ssh目录中,我有id_rsa和id_rsa.pub文件,需要在本地计算机上创建authorized_keys文件吗?
这是我运行ssh-vvv-i id_rsa[youruser]@[yourLinode]时得到的结果
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).
答案1
PubKeyAuthentication设置客户端
- 生成密钥
ssh-keygen
- 将ssh配置为使用密钥
vim ~/.ssh/config
- 将密钥复制到服务器
ssh-copy-id -i /path/to/key.pub SERVERNAME
步骤2中的配置文件应该有类似于以下的内容:
Host SERVERNAME
Hostname ip-or-domain-of-server
User USERNAME
PubKeyAuthentication yes
IdentityFile ./path/to/key
答案2
有时问题来自权限,例如如果要以root的身份登录,/root
和.ssh
,否则,sshd将无法读取它们,因此无法判断用户是否被授权登录。
在你的主目录中:
chown -R your_user:your_user .ssh
至于权限,.ssh使用700,authorized_keys使用600
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
相关文章