11

My company has multiple domains and I log into my local machine with one set of credentials, but often when accessing certain network resources I need to use a different set of credentials. In Windows I would use RunAs where I have the option to run the entire process as under a different set of credentials or I could tell it to only impersonate the other user over the network (runas /netonly).

Is there something like this in Linux?

3 Answers 3

27
$ sudo -u <username> <command>

That will run the specified command as the user specified. It's not an exact drop-in for Windows' RunAs function, though, as that incorporates Kerberos authentication as well as for tasks that connect to remote hosts.

5
  • @Mark: look into the different pam authentication modules to add network authentication support (pam_krb5 and pam_ldap are a good place to start) Apr 26, 2011 at 18:44
  • ok, but when I try sudo -u [domain2]\[username] it tells me 'unknown user: [domain2][username]' Apr 26, 2011 at 19:07
  • @Mark - that would be becuase by default, linux hosts know nothing of your AD/Windows environment. It's certainly possible to configure linux to use AD for authentication, but that's a separate question.
    – EEAA
    Apr 26, 2011 at 19:10
  • you're right, I've awarded the points and I'll post a new question. Apr 26, 2011 at 19:16
  • 2
    @Mark Sounds good. Before you post a new question, though, search through old ServerFault questions. There are scads of them relating to integration of linux and Windows.
    – EEAA
    Apr 26, 2011 at 19:21
7

sudo or su

1
  1. You can use the runuser command. Notice that you have to be a root user to use it:
runuser -l  userNameHere -c 'command'  
runuser -l  userNameHere -c '/path/to/command arg1 arg2'  
runuser -u user -- command1 arg1 arg2
  1. You can use the su command. This will work also with a non-root user:

su - anotherUser

See the link for more details:
https://www.cyberciti.biz/open-source/command-line-hacks/linux-run-command-as-different-user/

You must log in to answer this question.

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