如何在只有一个登录用户的`sudo bash`脚本时切换用户?

时间:2021-07-07 19:14:39

标签: bash shell sudo

我的系统是 debian 10,只有一个登录用户 boy 具有 sudo 权限。

##!/bin/bash
##root cannot log in
set -e
#expect root
whoami
user='boy'
su $user
#expect 'boy',but not
whoami
su - root
#expect root,but not
whoami

当我 sudo bash ./***.sh 在 bash 脚本之上运行时,预期输出为:

root
boy
root

sudo bash脚本只有一个登录用户时如何切换用户?

0 个答案:

没有答案