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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:16:44  来源:igfitidea点击:

Bash script to switch the user

linuxbash

提问by Gopu

I am having a cent-OS server with 5 accounts: developer, user1,user2,user3and user4. All the user home directories are under /homelike /home/developer, /home/user1, /home/user2, /home/user3and /home/user4. I want to create a 4 scripts: user1.sh, user2.sh, user3.shand user4.shinside the /home/developerfolder. When the user developerrun the script user1.sh, he switches to the user1and cdto 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服务器:developeruser1user2user3user4。所有用户的主目录下都/home一样/home/developer/home/user1/home/user2/home/user3/home/user4。我想创建一个脚本4: ,,和里面的文件夹。当用户运行该脚本,他切换到和到的主目录()等为剩余的脚本。背后的想法是阻止开发人员访问 root 并允许通过简单地执行具有该用户名的命令切换到其他用户的主目录。是否可以?user1.shuser2.shuser3.shuser4.sh/home/developerdeveloperuser1.shuser1cduser1/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 - otherUsercould work but I haven't tried

我想类似的东西sudo su - otherUser可以工作,但我还没有尝试过