Freebsd – How to switch one user to another in Freebsd

freebsdusers

How can I switch one user to another in Freebsd?

For examples, I am user david now and I want to change to user Bob.
This is a personal OS for my study. not a server.
I searched it, but only got sites about how to create new user.
Thank you.

Best Answer

You have many options, including su, login, ssh, and sudo.

The easiest way is to run su, e.g.

$ su otheruser

or

$ su - otheruser

The first one sets your user to otheruser.

The second one sets you user to otheruser and sources otheruser's login scripts (e.g. .profile for sh or .login for csh), to make it seem like you've logged in as that user.

If otheruser is root (or is missing, which also means root), then you will need to be in the wheel group, as per the man page:

by default only users in the wheel group can switch to UID 0 (root).

Another way is login, e.g.

$ login
login: otheruser
Password:   

Or, if you are running sshd, you could use ssh, e.g.

$ ssh otheruser@localhost

Or you could install sudo using ports.

# cd /usr/ports/security/sudo
# make && make install

or packages

# pkg_add -r sudo

See the sudo man page for details of how to run it.

Related Question