Linux 用于切换用户的 Bash 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19806215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash script to switch the user
提问by Gopu
I am having a cent-OS server with 5 accounts: developer
, user1
,user2
,user3
and user4
. All the user home directories are under /home
like /home/developer
, /home/user1
, /home/user2
, /home/user3
and /home/user4
. I want to create a 4 scripts: user1.sh
, user2.sh
, user3.sh
and user4.sh
inside the /home/developer
folder. When the user developer
run the script user1.sh
, he switches to the user1
and cd
to the home directory of user1
(/home/user1
) and so on for the remaining scripts. The idea behind is to keep the developer from the root access and allow switch to other user's home directory by simple executing a command with that user's name. Is it possible?
我有5个帐户一分钱-OS服务器:developer
,user1
,user2
,user3
和user4
。所有用户的主目录下都/home
一样/home/developer
,/home/user1
,/home/user2
,/home/user3
和/home/user4
。我想创建一个脚本4: ,,和里面的文件夹。当用户运行该脚本,他切换到和到的主目录()等为剩余的脚本。背后的想法是阻止开发人员访问 root 并允许通过简单地执行具有该用户名的命令切换到其他用户的主目录。是否可以?user1.sh
user2.sh
user3.sh
user4.sh
/home/developer
developer
user1.sh
user1
cd
user1
/home/user1
采纳答案by Bruce
I suppose you're looking at su - otherUser
我想你在看 su - otherUser
Of course, you'll have to provide the password of the other user.
当然,您必须提供其他用户的密码。
I suppose that something like sudo su - otherUser
could work but I haven't tried
我想类似的东西sudo su - otherUser
可以工作,但我还没有尝试过