sudo

Using sudo with for loop

左心房为你撑大大i 提交于 2020-12-29 05:17:27
问题 I want to run a simple for loop command with sudo, but it isn't working: sudo -i -u user for i in /dir; do echo $i; done I get the following error: -bash: syntax error near unexpected token `do' Probably a very simple thing I am overlooking. Any help? 回答1: sudo wants a program (+arguments) as a parameter, not a piece of shell script. You can do this, though: sudo -i -u user sh -c 'for i in /dir; do echo $i; done' Note the single quotes. If you used double quotes, your shell would try to

sudo,su,passwd,chsh命令详解

对着背影说爱祢 提交于 2020-12-16 10:44:08
sudo意思就是super-user do,让当前用户暂时以管理员的身份root来执行这条命令。 su是用来改变当前用户。 su root,就是将当前用户切换为roo。用了su root之后,下面所有的命令就可以不用打sudo了,因为当前用户已经是管理员root了。 root 用户为根用户,也就是 系统管理员。root拥有全部权限。 su [用户名] 切换到其它用户,默认切换到root用户。提示密码为将切换用户密码。可选参数: -f 快速切换,忽略配置文件 -l 重新登录 -p 不更改环境变量 -c <命令> 切换后执行命令,并退出切换 sudo [命令] 以其它用户的身份执行命令,默认以root的身份执行。提示密码为当前用户密码. 可选参数: -s 切换为root shell -i 切换为root shell,并初始化 -u <用户名|UID> 执行命令的身份 -l 显示自己的权限 passwd [用户名] 设定用户密码 . 可选参数: -d 清除密码 -l 锁定用户 -e 使密码过期,在下次登录时更改密码 -S 显示密码认证信息 -x <天数> 密码过期,最大使用时间-n <天数> 冻结密码,最小使用时间-s 更改登录Shell-f 更改用户信息 chsh [-s <Shell>] [用户名] 更改登录Shell 补充: 1.sudo的缺省配置 默 认时, Ubuntu为

Gitlab CI invokes docker install.sh and always runs instruction with Sudo

微笑、不失礼 提交于 2020-12-15 04:36:47
问题 I am trying to run gitlab ci which contains custom php image. The before_script invokes docker_install.sh In docker_install.sh I executed whoami it gives "docker". I tried to list down groups it gives "docker sudo". When I try to execute further instructions in docker_install.sh file, like cp ci/php.ini /etc/php/7.4/cli/php.ini It does not execute and gives error cp: cannot create regular file '/etc/php/7.4/cli/php.ini': Permission denied If I do sudo cp ci/php.ini /etc/php/7.4/cli/php.ini it

Passing empty arguments to sudo -i

只谈情不闲聊 提交于 2020-12-12 10:36:32
问题 Here is an example bash script that I would like to run using sudo -i : #!/bin/bash echo "arg 1: $1" echo "arg 2: $2" When I run this command normally with one empty argument, it runs as expected: $ /tmp/args.sh "" two arg 1: arg 2: two With plain sudo, I get the expected result: $ sudo /tmp/args.sh "" two arg 1: arg 2: two However if I use -i (to pick up the user's shell and login scripts), suddenly the first argument disappears: $ sudo -i /tmp/args.sh "" two arg 1: two arg 2: And I cannot

Killing sudo-started subprocess in python

瘦欲@ 提交于 2020-08-24 07:45:13
问题 I am running with a user that can make root-level calls without having to supply a password. My user currently does something like this pr = subprocess.Popen("sudo sleep 100".split()) sleep(5) pr.kill() but that leads to this error because the user isn't root so it can't kill a root process Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/subprocess.py", line 1572, in kill self.send_signal(signal.SIGKILL) File "/usr/lib/python2.7/subprocess.py",