设置身份文件但仍然不能没有环境变量ssh


0

我正在尝试在crontab上设置一个scp作业,并通过控制台测试该功能。 crontab不会导入环境变量,所以我正在测试它 env -i,还要通过导入身份密钥 ssh -i

env -i sh -c "ssh -i /home/myname/.ssh/id_rsa box hostname"

但是,这不起作用,我只是得到了 Permission denied (publickey)。我认为我的密钥设置正确。我将公钥附加到远程框的authorized_key文件中。

在这两台机器上,我在/ etc / ssh / sshd_config中设置了这些:

PubkeyAuthentication yes
RSAAuthentication yes

这是我在远程主机上的auth.log中得到的错误:

Sep 13 21:45:13 box sshd[59109]: userauth-request for user myuser service ssh-connection method publickey remote_ip <someip> remote_port 51635 attempt 1 failures 0 [preauth] session=box:57d87369.6185

EDIT2:

跑步时......

SSH_AUTH_SOCK="" ssh -vv -i /home/myuser/.ssh/id_rsa myuser@myhost

我知道了...

debug2: key: /home/myuser/.ssh/id_rsa (0x7fc5ee0d15a0), explicit
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/myuser/.ssh/id_rsa
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).

我尝试手动将文件附加到authorized_keys,后来也尝试了ssh-copy-id。 .ssh /目录是700


为什么你需要环境。变量?
Jakuje

我想阻止环境变量,因为这是crontab的作用。
barrrista

你如何正常认证?你的密钥有密码吗?
Jakuje

我登录时通常使用ssh-agent转发。但是crontab不会选择它,因此我创建了一个密钥对并指向它。我收到一个错误,我将更新有问题。
barrrista

如果您没有ssh-agent中的密钥,您是否能够使用这个新密钥对登录? SSH_AUTH_SOCK="" ssh -i /home/myname/.ssh/id_rsa hostname
Jakuje
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.