Alex Kaloostian

Apple Certified Master Trainer | Systems Integrator | Video Editor | Motion Graphics Artist

Command Line 11 – switching users

Leave a comment

In past lessons, we talked about logging into the command line, and using sudo. When you open the terminal or otherwise access the command line, the Terminal app will automatically log you in as the person you are currently logged into your Mac as. In other words, if you’re logged into your Mac as John, when you open the Terminal, you’ll be logged into the command line as John. The prompt will tell you what computer you’re on, and who you’re logged in as:

Here you can see that my computer name is Dora, I’m currently in my home folder (that’s what the ~ is for) and I’m logged in as overstim.

But sometimes you want to log in as a different user. Lets say you wanted to see what was inside Bruce’s Documents folder:

You can’t, because you’re not Bruce. Even if you know Bruce’s password, it won’t work. You could log out of your Mac, log back in as another user, then launch the Terminal again, but that sounds tedious. Let’s just do it right here in the terminal! To switch to another user in the Terminal, use the su command.

Just type su, space, username, press return, enter your password, it’s that easy. What if you don’t know the user’s password? Well, this isn’t some sneaky back door, you need the user’s password to log into the Mac as them, and this is no different.

You may have noticed, that when you switch users, the prompt no longer tells us who we are. Bummer. But you can still find out who you are with the whoami command:

Now, try listing the contents of Bruce’s Documents folder. Note: just because you switched to the user Bruce, doesn’t mean you’re magically transported into Bruce’s home folder. You still have to be specific about whose Documents folder you wish to view:

That’s about it. Oh, well there is one more thing. You can’t su to the root user because root is disabled on all Macs. However, remember sudo from last lesson? sudo lets you perform any task as root for 5 minutes. But you can stay permanently authenticated with sudo, and that’s just the same as being sudo. We do this with the sudo -s command. like sudo, sudo -s can only be performed by an admin.

Advertisements

Author: alexkaloostian

I'm a video editor, motion graphics designer and Mac IT consultant in the Boston area.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s