篇首语:本文由小常识网(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”命令的主要内容,如果未能解决你的问题,请参考以下文章