When I switch from root user to a user (automatically created when installing git-auto-deploy) with

sudo -u git-auto-deploy /bin/bash I always get this error:

bash: /root/.bashrc: Permission denied

I created a user home directory, and put a .profile in it with the following (ran source on it too):

export HOME=/srv/users/git-auto-deploy

The command finger git-auto-deploy gives the following output:

Login: git-auto-deploy                  Name:
Directory: /srv/users/git-auto-deploy   Shell: /bin/bash
Never logged in.

When logged in as this user, the env command still lists incorrect directory:


What am I doing wrong?

  • Does it work if you add -l option to your sudo? – Julie Pelletier Dec 29 '16 at 15:49
  • No, it just outputs /bin/bash, doesn't even do the user switch. – montrealist Dec 29 '16 at 16:18

Use sudo -s -H -u git-auto-deploy.

sudo by itself does not change the value of HOME, but does so when -H is used. This is why you're getting that "Permission denied" error. The user can't access root's home directory (and shouldn't be able to either).

The -s option makes sudo start whatever shell is configured as the login shell for the specified user (i.e. no need to explicitly run /bin/bash).

  • Makes sense, only sudo -s -H executes the git-auto-deploy service, it doesn't perform a user switch. – montrealist Dec 29 '16 at 16:16
  • 1
    @montrealist see updated answer. There was a missing option. – terdon Dec 29 '16 at 16:17

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.