开发者

Switch Users in unix automatically

开发者 https://www.devze.com 2023-02-07 20:15 出处:网络
This might be a newebie question. I would like to automatically switch 开发者_如何转开发between users. I know that we can use \"expect\" programming. Is there any alternative way ?Using su has already

This might be a newebie question. I would like to automatically switch 开发者_如何转开发between users. I know that we can use "expect" programming. Is there any alternative way ?


Using su has already been mentioned:

su - <username>

But more restricted access to other user accounts can be granted using sudo:

sudo -u <username> <command>

Sudo supports many options. See /etc/sudoers and man sudoers.

To always run an executable or a script as another user, without using any tools like su or sudo, or to build your own tool for your current purposes, use the setuid mode:

chown <username> <executable>
chmod u+s <executable>
./<executable>

For example:

$ id -un
atnnn
$ cp /usr/bin/id .
$ sudo chown nobody id       
$ sudo chmod u+s id
$ ./id -un
nobody


It depends on what you really want, and how you're accessing your machine. It is easy enough to create windows (xterms or whatever) and arrange for different terminals to run as different users - at least after you've created them. You can use 'su' or (better) 'sudo' to become another user. (I'm assuming you're authorized to become that other user - it isn't the ID of a colleague, but of some test user that you need to experiment with.)

If you want to switch between terminal sessions as different users at a single window, then you have to work a bit harder. There are programs to do that: it used to be shl (shell layers) and I think the modern equivalent is GNU Screen. I've not used GNU Screen (and I haven't used shl since about 1990); I work with different terminals connected as, or running as, the different users when I need to work as multiple users.

0

精彩评论

暂无评论...
验证码 换一张
取 消