使用刀具独奏与非root用户进行sudo访问,无需密码

时间:2014-09-08 15:44:20

标签: ssh chef ubuntu-14.04 knife-solo

当我对具有sudo访问权限的非root用户使用chef knife solo时,它总是会询问用户的密码。但是,我已关闭对该服务器的密码访问。

$ bundle exec knife solo cook supersecretuser@productionserver -VV
Starting 'Run'
Running Chef on productionserver...
Checking Chef version...
DEBUG: Initial command sudo chef-solo --version 2>/dev/null | awk '$1 == "Chef:" {print $2}'
DEBUG: Initial command sudo -V
DEBUG: Running processed command sudo -V
DEBUG: sudo -V stdout: Sudo version 1.8.9p5

DEBUG: sudo -V stdout: Sudoers policy plugin version 1.8.9p5
Sudoers file grammar version 43

DEBUG: sudo -V stdout: Sudoers I/O plugin version 1.8.9p5

DEBUG: Running processed command sudo -E -p 'knife sudo password: ' chef-solo --version 2>/dev/null | awk '$1 == "Chef:" {print $2}'
Enter the password for supersecretuser@productionserver: 

我已将ssh密钥添加到服务器,并且能够使用ssh supersecretuser@productionserver ssh进入该服务器而无需密码。

我在我的登台服务器上使用了chef knife solo和root用户,它运行正常。

我尝试使用-i选项显式传递我的ssh密钥,chef knife solo cook supersecretuser@productionserver -i ~/.ssh/id_rsa.pub并且刀独奏似乎没有使用它。关于下一步该尝试的任何想法?

注意:我正在展示cook,因为那就是我所处的位置。我做了一个prepare并且它有效,因为我还没有关闭密码访问 - 这发生在我的第一个cook - 所以我只能输入密码。

1 个答案:

答案 0 :(得分:2)

你在ssh和sudo之间搞乱,检查你的sudoers文件中的supersecretuser条目应该是这样的:

#Vagrant entry to allow sudo from vagrant
vagrant ALL=(ALL) NOPASSWD: ALL

这里允许vagrant用户在没有密码的情况下sudo任何命令。