简体   繁体   中英

Bash script to switch the user

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?

I suppose you're looking at 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM