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.

2 Answers 2


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

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

$ su otheruser


$ 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

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.


su can be used for this purpose. If you want to become user bob you would type:

su bob

su will then ask for a password, which is bob's password, not yours. When invoked without arguments it tries to become superuser (same as su root). You may have to add your user account to the wheel group, or change some configuration so that the normal user can use su.

I usually do:

sudo su - bob

so I won't need to know the password of the other user (Note: I'm a Linux user and I'm not sure how different BSD is).

  • wheel is only required to su to root.
    – Mikel
    Commented Apr 10, 2011 at 22:45
  • 2
    Why sudo su - bob instead of just sudo -s -u bob?
    – gelraen
    Commented Apr 11, 2011 at 17:37
  • Hmm I guess it's just a habit :)
    – phunehehe
    Commented Apr 12, 2011 at 2:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .