Ubuntu Server 12.04

On a remote server that I ssh into I have set up a special user with:

sudo adduser --system --disabled-login --disabled-password --group suser

to run some maintenance functions. On occasions I su into a login session for suser with:

sudo su -l suser -s /bin/bash

to do some tasks... however I particularly want to be able to run some git commands via:

sudo su suser -c <COMMAND>

from my real user and no login to the suser.

Unfortunately I haven't been able to determine HOW I go about that. I have tried the only ways that makes sense to me:

sudo su suser -c git clone https://example.com/repos/project.git
sudo su suser -c "git clone https://example.com/repos/project.git"
   or even
sudo su suser -c mkdir /home/suser/test
sudo su suser -c "mkdir /home/suser/test"

but nothing happens and I return to prompt. Can anyone assist or explain why this isn't possible?


The problem is that suser was created with /bin/false as its default shell. Therefore, when you try to run commands as suser through sudo, the system attempts to run them using /bin/false/ which is not a real shell and fails. You can either set a shell for suser or you can specify it on the command line when you run sudo. Alternatively, you can use sudo's -u option.

  1. Use -u:

    sudo -u suser mkdir /home/suser/foo

    This works because by default, sudo uses /bin/bash (or whatever you have set the default $SHELL to be). Therefore, it will execute a command as suser but using bash, so the command is correctly executed.

  2. Set suser's default shell:

    sudo chsh suser 

    Enter /bin/bash (or whatever you prefer) in the prompt that will appear. You should now be able to launch commands as suser:

    sudo su suser -c "mkdir /home/suser/test"
  3. Set the shell explicitly:

    sudo su suser -s /bin/bash -c "mkdir /home/suser/test"
  • That's it... facepalm I was under the mistaken impression that since I wasn't doing -l, that I was keeping the current shell and environment. Thank you! – JDex Jun 19 '13 at 12:34

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.