Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute a command as another user?

Status
Not open for further replies.

lamsf

Technical User
Jul 27, 2003
103
US
Hi, a simple question. Could not recall the command...

If I want to execute a command as another user, what is the way to do it?

For eg. I would like to execute command "ls" as user ABC, I would do the following:

su - ABC
(put in the password, etc)
(at ABC user prompt)
ls

I know there is a short way to do it, but could not recall.
Pls help.
Thanks.
 
From man pages for su -

To execute command with the temporary environment and permissions of user bin, type:

example% su - bin -c "command args"
 
The other option is sudo. If you look up sudo you should find docs on how to set it up and use it. I prefer being able to log in as myself and su to root and then work, but some companies don't let you do that for security. So being able to use sudo let's you run any command as either root or some user you have specified in the sudo configuration.

A command would be simple:
# sudo ls -la
Password:
#

------------------------------------------------------------------------------------------------------------------
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."
Albert Einstein
 
Thanks SANEngInCO and dandan123 for the reply.
I will try it out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top