sh 自动化“sudo su - user”命令

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 自动化“sudo su - user”命令相关的知识,希望对你有一定的参考价值。

https://superuser.com/a/243510

If you want to use sudo su - user without a password, you should (if you have the privileges) do the following on you sudoers file:

<youuser>  ALL = NOPASSWD: /bin/su - <otheruser>
where:

<yourusername> is you username :D (saumun89, i.e.)
<otheruser> is the user you want to change to
Then put into the script:

sudo /bin/su - <otheruser>
Doing just this, won't get subsequent commands get run by <otheruser>, it will spawn a new shell. If you want to run another command from within the script as this other user, you should use something like:

 sudo -u <otheruser> <command>
And in sudoers file:

<yourusername>  ALL = (<otheruser>) NOPASSWD: <command>
Obviously, a more generic line like:

<yourusername> ALL = (ALL) NOPASSWD: ALL
Will get things done, but would grant the permission to do anything as anyone.

以上是关于sh 自动化“sudo su - user”命令的主要内容,如果未能解决你的问题,请参考以下文章

sh 在Mac OSX中将所有文件重命名为小写

linux自动删除7天前的文件

sh 用于将.css.scss重命名为.scss的Shell脚本

sh 使用bash和linux工具将文件夹中的文件重命名为文件夹名称。

Shell脚本自动编译打包Gradle项目并docker部署

今天介绍一个渐变的方法,在shell里面自动生成注释简介