Running a command as a specific User, even if that User does not have shell access


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » System Level » SSH

Running a command as a specific User, even if that User does not have shell accessLast Modified: Jun 6, 2017, 10:20 pm
Sometimes you'll need to run some commands as a specific User, but that User might not have a shell setup.
Instead of turning on ssh for that User, you can instead use sudo to open a new shell, running as that User.

Say you want to open a shell as .

To do this, you'd login to ssh as root, and run:

sudo -H -u fred /bin/bash -c '/bin/bash'


To confirm it worked, run the command:

/usr/bin/id

to see which uid the current shell is running as.

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST