标签: sudo

如何以root(sudo)身份运行shell脚本?

我有一个在存储库用户下运行的SVN存储库服务器.我希望在每次提交后操作后运行脚本.我写了一个shell脚本,它在每次提交后从钩子运行.它需要以root身份运行.这就是我在脚本中使用sudo的原因,但它没有用.有没有办法以root身份运行脚本?

sudo su
echo "password"
svn export --force file:///home/repository/trunk/ /home/memarexweb/public_html/devel/
chmod -R 777 /home/memarexweb/public_html/devel/
Run Code Online (Sandbox Code Playgroud)

svn shell sudo

7
推荐指数
3
解决办法
4万
查看次数

使用sudo时jenkins中的身份验证错误

我在jenkins中有sh脚本,它有sudo ssh命令,我收到了这个错误

Warning: Identity file key.pem not accessible: Permission denied.
Host key verification failed.
sudo: no tty present and no askpass program specified
Run Code Online (Sandbox Code Playgroud)

我找到了添加的解决方案

jenkins ALL=(ALL) ALL
Run Code Online (Sandbox Code Playgroud)

/ etc/sudoers中的这些行仍然无法正常工作.

deployment ssh ubuntu sudo jenkins

7
推荐指数
1
解决办法
2万
查看次数

非特权,非root用户,用于启动或重新启动webserver服务器,例如没有root或sudo的nginx

我正在使用capistrano来部署rails web应用程序.我想尽可能少地为网络服务器上的部署用户提供权限.除了重启网络服务器之外,我能够以非特权用户的身份做我需要做的一切.

我在ubuntu服务器上这样做,但是这个问题并不是我的用例(rails,capistrano,部署)所特有的,而且我已经看到很多解决这个问题的方法似乎涉及不良的安全实践.想知道其他人是否可以审查我的解决方案并建议它是否安全?

首先,没有必要,但我不知道为什么/etc/init.d/nginx需要其他用户进行任何(甚至读取)访问.如果他们需要阅读它,让它们成为root(通过sudo或其他方式),所以我:

chmod 750 /etc/init.d/nginx
Run Code Online (Sandbox Code Playgroud)

由于所有权是所有者root,组root(或者可以设置为chown root:root /etc/init.d/nginx)只有root,或者用户正常sudo'ed,可以读取,更改或运行/ etc/init .d/nginx,我不打算给我的部署用户任何这样广泛的权利.相反,我只是给部署用户提供特定的sudo权限来运行控制脚本/etc/init.d/nginx.他们将无法运行编辑器来编辑它,因为他们只能执行该脚本.这意味着,如果有人以部署用户的身份访问我的盒子,他们可以重新启动和停止等nginx进程,但是他们不能做更多的事情,比如改变脚本来做很多其他的,邪恶的事情.

具体来说,我这样做:

visudo
Run Code Online (Sandbox Code Playgroud)

visudo是用于编辑sudoers文件的特定工具,您必须具有sudoer权限才能访问它.

使用visudo,我补充说:

# Give deploy the right to control nginx
deploy ALL=NOPASSWD: /etc/init.d/nginx
Run Code Online (Sandbox Code Playgroud)

检查sudo手册页,但据我了解,第一列是给予sudo权限的用户,在本例中为"deploy".ALL提供来自所有类型的终端/登录的部署访问(例如,通过ssh).最后,/ etc/init.d/nginx,ONLY赋予部署用户root权限以运行/etc/init.d/nginx(在这种情况下,NOPASSWD意味着没有密码,这是我无人值守部署所需的) .部署用户无法编辑脚本以使其变得邪恶,他们需要FULL sudo访问才能执行此操作.事实上,没有人可以,除非他们有root权限,在这种情况下,有一个更大的问题.(我测试过用户部署在执行此操作后无法编辑脚本,所以你应该这样做!)

你们有什么感想?这有用吗?有没有更好的方法来做到这一点?我的问题是类似这个这个,但提供了比我在那里发现,如果对不起它太重复,如果是的话,我会删除它,虽然我也要求不同的方法更多的解释.

permissions ubuntu sudo capistrano ruby-on-rails

7
推荐指数
1
解决办法
5267
查看次数

如何允许bash -c为sudoers(后跟多个命令)?

我在/ etc/sudoers中有这个:

%wheel myhostname =NOPASSWD: /bin/bash -c "echo foo && echo bar", \
                             /bin/bash -c echo foo
Run Code Online (Sandbox Code Playgroud)

sudo /bin/bash -c echo foo没有提示输入密码的情况下执行工作.

但是,sudo /bin/bash -c "echo foo && echo bar"仍然要求输入密码.

我尝试了很多变化,但没有被接受.

哪里出错?/如何允许-c后跟多个命令?

bash sudo sudoers

7
推荐指数
2
解决办法
2067
查看次数

Vagrant是否应该为每个命令都要求sudo?

简而言之:我每次执行没有'sudo'的任何Vagrant命令时都会遇到权限错误 - 从.vagrant upvagrant provision.这是预期的行为吗?

/Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:295:in `unlink': Permission denied - /Users/Cibulka/Sites/.vagrant/machines/default/virtualbox/id (Errno::EACCES)
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:295:in `delete'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:295:in `id='
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:438:in `state'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/providers/virtualbox/action/created.rb:11:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builder.rb:116:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `block in run'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/util/busy.rb:19:in `busy'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `run'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builtin/call.rb:43:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/providers/virtualbox/action/check_virtualbox.rb:17:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builder.rb:116:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `block in run'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/util/busy.rb:19:in `busy'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `run'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:196:in `action_raw' …
Run Code Online (Sandbox Code Playgroud)

permissions macos sudo chown vagrant

7
推荐指数
1
解决办法
8271
查看次数

云平台 - sudo:无法解析主机

我在Amazon-EC2和openstack上使用linux作为基于云的服务器.试图运行时:

sudo chhown ubuntu somepath
Run Code Online (Sandbox Code Playgroud)

我偶尔会得到这个错误:

sudo:无法解析主机

互联网上对此问题的大多数答案都是编辑/ etc/hosts文件.

但是,我会自动部署我的服务器.除此之外,我没有使用"localhost"登录,而是登录我的AWS公共DNS:

ssh -i mykey.pem ubuntu@ec2-12-34-56-78.eu-central-1.compute.amazonaws.com
Run Code Online (Sandbox Code Playgroud)

所以我不能简单地插入localhost,更不用说我的IP可以在我重置我的机器后改变.(不要为每台服务器"浪费"我宝贵的浮动IP)

此外,我一次部署数十台服务器,因此我无法负担编辑文本文件的手动步骤.是否有针对此问题的自动修复程序?最近我开始使用openstack,问题也存在.

ubuntu sudo amazon-ec2 openstack

7
推荐指数
1
解决办法
7778
查看次数

Git命令在OSX上需要sudo

我已经从我的MBP工作回到了我的家庭MBP.工作一个允许运行git命令而不需要sudo.但我发现这是我家用机器的要求.

我宁愿能够在没有sudo的情况下运行git命令.

我查看了/ usr/bin中的git命令,它们都有rwxr-xr-x(755),并且由root和group wheel拥有.我想我可以将其更改为rwxrwxrwx(777),但我想知道是否有更好的方法.我想把我的用户添加到轮组; 但会有其他副作用吗?

git macos sudo

7
推荐指数
1
解决办法
5904
查看次数

Glassfish不会从Intellij开始,除非我用sudo运行Intellij

标题说明了一切......只是试图让玻璃鱼起来走了.这是我得到的错误

Detected server admin port: 4848
[2015-04-06 07:37:56,138] Artifact java_web_app:war exploded: Server is not connected. Deploy is not available.
Detected server http port: 8080
Command start-domain failed.
JVM failed to start: com.sun.enterprise.admin.launcher.GFLauncherException: The server exited prematurely with exit code 1.
Before it died, it produced the following output:

This subcommand requires root privileges: bsexec
Run Code Online (Sandbox Code Playgroud)

当然有办法解决这个问题吗?我真的不想每次都用sudo运行Intellij.

sudo glassfish intellij-idea

7
推荐指数
3
解决办法
4203
查看次数

为什么我不能在没有使用Python和pip的sudo的情况下做一些事情?

当我使用pip时,它通常在没有sudo的情况下不起作用.我经常看到人们使用没有sudo的pip,所以我做错了什么?

我读过不建议用sudo安装pip包.我知道virtualenv我可以使用没有sudo的pip,但要安装virtualenv我必须首先使用sudo.

当我尝试安装没有sudo的pip时,我得到:

PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.4/dist-packages/pip'
Run Code Online (Sandbox Code Playgroud)

尝试安装烧瓶时pip3 install flask:

PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.4/dist-packages/werkzeug'
Run Code Online (Sandbox Code Playgroud)

python sudo pip virtualenv

7
推荐指数
2
解决办法
5569
查看次数

在Fabric2中的Sudo

我想重现我运行的旧Fabric1脚本的行为

sudo('useradd -m -u --groups mygroup myuser')
Run Code Online (Sandbox Code Playgroud)

在这种情况下,远程机器(Ubuntu AWS实例)会提示我输入我的sudo密码,我可以输入它.即使错误输入后的重复提示也可以.之后,Fabric1将通过保持连接打开来保持该密码.

在我的新的Fabric 2.x脚本中,我在@task中使用

c.sudo('useradd -m -u --groups mygroup myuser')
Run Code Online (Sandbox Code Playgroud)

我仍然收到用户提示,但它不等待我的响应,我无法输入密码,并且它按预期失败

invoke.exceptions.AuthFailure: The password submitted to prompt '[sudo] password: ' was rejected
Run Code Online (Sandbox Code Playgroud)

使用--prompt-for-sudo-password参数具有相同(或无效).

我也试过了

run('sudo useradd -m -u --groups mygroup myuser')
Run Code Online (Sandbox Code Playgroud)

并收到

sudo: no tty present and no askpass program specified
Run Code Online (Sandbox Code Playgroud)

我最好不要在没有Fabric 1.x的情况下在一台完美运行的机器上设置askpass程序(除非我能从我的脚本那样做,这需要sudo,我猜).

我一直在撞墙试图使用复杂且没有完善记录的配置系统,但没有成功.

我错过了什么?如果需要额外的配置,我想知道配置文件的语法以及放置该文件的位置,以便通过fab CLI命令获取它.

python sudo fabric

7
推荐指数
1
解决办法
1275
查看次数