4

I am creating a bash script that requires to run commands as a specific user. As a result I am using the command:

runuser

I have tested this script and it works perfectly in Ubuntu Server 14.10. However, when testing it on 14.04 and 12 I run into the following error:

runuser: command not found

This happens any time the runuser command is used.

I am using the following command to create a new user:

adduser --no-create-home --home "/home/$homedir" --disabled-password --gecos "$realname" "$uname" ; usermod -p "$passwd" "$uname"

Is there something specific that needs to be specified when creating the new user? Is there a particular dependency that is missing?

Edits For Questions:

Output of echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/loc‌​al/games

Output of ls -l /sbin/runuser

ls: cannot access /sbin/runuser: No such file or directory

The reason why I want to use runuser vs su is because of the following:

When using runuser I can run the following commands:

runuser user -c 'cd'
runuser user -c 'wget http://file.com'

Whereas with su I have to chain the commands like this:

su user -c 'cd; wget http://file.com'
  • 1
    Can't you just use sudo -u instead? Also, please add the output of echo $PATH as the user who runs runuser and the output of ls -l /sbin/runuser. – terdon Nov 22 '14 at 20:06
  • sudo -u doesn't work as well and I'm finding I have to put all the commands I need to use as 1 and separate them by ;. I'm running everything as the root user and here is the output: # echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games and # ls -l /sbin/runuser ls: cannot access /sbin/runuser: No such file or directory – user3024130 Nov 22 '14 at 20:18
  • Welcome to Unix & Linux! Please edit your question to add extra information, it is hard to read and easy to miss in the comments. – terdon Nov 22 '14 at 20:26
  • Edit your question with the contents of your comment about sudo - it will be better to read. – guntbert Nov 22 '14 at 21:50
  • I've added my comments for sudo – user3024130 Nov 22 '14 at 22:17
11

runuser is a recent command, it appeared in util-linux 2.23. Ubuntu 14.04 ships util-linux 2.20, so it doesn't have this command yet.

runuser isn't very useful. Just use su instead. Note that the command runuser user -c 'cd' doesn't actually do anything — the scope of cd does not extend to the next call to runuser. You'd have to use runuser user -c 'cd && wget http://file.com' anyway. Use su user -c 'cd && wget http://file.com' instead.

  • 2
    runuser is useful as it is not setuid while sudo or su are. As such it does not have the same restrictions as sudo. For example, under Ubuntu sudo configuration does not allow to pass open file descriptor to the command besides stdin/stdout/stderr even if root runs the command, while runuser does not have such restrictions. Plus su -c always runs a shell while runuser -u can run the command directly. – Igor Bukanov Dec 18 '15 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.