How to enable sudo commands over SSH without asking password?如何ssh到远程服务器执行sudo命令时不输入密码

问题:

I have server A and server B (both Ubuntu 10.04 LTS) doing different tasks. Server A needs to poke Server B, which generates a file and scp's it back to server A when done. This is all in-house and I am not too concerned about security issues. SSH Key exchange is already performed between servers A and B and works fine.

On server B, the script generateOfflineSig looks like

#!/bin/bash
echo "in script"
sudo apt-offline set offline_package.sig --install-packages "$0"
echo "after sudo"
scp offline_package.sig jeff@servera:/tmp

Also on server B, visudo has this entry:

jeff ALL=NOPASSWD: ALL

Which works if I execute sudo ls on Server B... no password asked.

Unfortunately SSH always asks for a password on Server A:

jeff@servera:~$ ssh -t jeff@serverb /home/jeff/generateOfflineSig "incron"
in script
[sudo] password for jeff:

Any ideas? This process can't be interrupted by password input.

 

回答:

It seems like I had a "typo" in the /etc/sudoers file...

jeff ALL=NOPASSWD: ALL

needed to be at the very end of file. Ubuntu Help only says Add (...) to the END of the file (if not at the end it can be nullified by later entries)

After that, password is never asked for "jeff's sudo commands, either locally or over SSH.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值