These files are owned by UID 99, which is the unknown user. These files were, perhaps, initially created by an account that is no longer on the system, or a "different version of yourself" that was migrated from a previous version of the OS, etc. To avoid confusion, when a normal user inspects these files, they appear to belong to whoever is viewing them. When root inspects them (via sudo
, for example), their actual owner is shown.
The following describes this in greater detail:
http://googlemac.blogspot.com/2007/03/user-99-unknown.html
sudo
can do just that for you :)
It needs a bit of configuration though, but once done you would only do this:
sudo -u user2 -s
And you would be logged in as user2 without entering a password.
Configuration
To configure sudo, you must edit its configuration file via: visudo
. Note: this command will open the configuration using the vi
text editor, if you are unconfortable with that, you need to set another editor (using export EDITOR=<command>
) before executing the following line. Another command line editor sometimes regarded as easier is nano
, so you would do export EDITOR=/usr/bin/nano
. You usually need super user privilege for visudo
:
sudo visudo
This file is structured in different section, the aliases, then defaults and finally at the end you have the rules. This is where you need to add the new line. So you navigate at the end of the file and add this:
user1 ALL=(user2) NOPASSWD: /bin/bash
You can replace also /bin/bash
by ALL
and then you could launch any command as user2 without a password: sudo -u user2 <command>
.
If you want to be able to switch to any user just use
user1 ALL=(ALL) NOPASSWD: /bin/bash
Update
I have just seen your comment regarding Skype. You could consider adding Skype directly to the sudo's configuration file. I assume you have Skype installed in your Applications folder:
user1 ALL=(user2) NOPASSWD: /Applications/Skype.app/Contents/MacOS/Skype
Then you would call from the terminal:
sudo -u user2 /Applications/Skype.app/Contents/MacOS/Skype
Best Answer
It turns out there was another exec "chmod" on the path, obscuring my own chmod.
The thing that made this difficult to see was that I'd used the metacharacter "~" in my PATH variable. Only some things will interpret a tilde in the PATH. The
which
program does not expand the tilde, sowhich chmod
told me that/bin/chmod
was the chmod on the path, but bash does expand the tilde, so it tried to run the other chmod (which did nothing.) Meanwhile,sudo
does not expand the tilde so it worked, and gave the impression of a permissions problem.Resolution: when adding subdirectories of your home directory to your
PATH,
use$HOME
instead of~
.