2

I am using a Debian 9 server.

Usually I access via ssh to a normal user (say user1) and su into root, because I disabled ssh into root. Lately I was setting up a git-server where I created a user git with the group git and restricted him to git-shell. Playing around a little while I added user1 to the group git like this:

usermod -aG git user1

This worked alright, user1 was member of the groups user1 and git. At the end I wanted to undo this, so I used:

usermod -G user1 user1

Shortly after this, I lost my internet connection and had to reconnect. I can ssh into user1 alright, but when using su to access root, there is an error:

user1@hostname:~$ su 
Password: 
Cannot execute git: No such file or directory
user1@hostname:~$

I included the information about git-shell, because I have no idea what else could be the reason. Hopefully it is not all lost and somebody can help me to regain control.

PS: There isn't any other root-like user, so sudo isn't working, since user1 "is not in the sudoers file".

PPS: I could reset the root password via VPS-login, but I am not quite sure whether this is going to work or make everything worse.

14
  • Can you try su -s /bin/sh to try to get a root shell?
    – doneal24
    Commented Jun 15, 2019 at 1:11
  • unfortunately same error...
    – Pratched
    Commented Jun 15, 2019 at 1:13
  • To work it some more, how about su -s /bin/sh -c /bin/sh? Seems like overkill but it's worth a try.
    – doneal24
    Commented Jun 15, 2019 at 1:23
  • Cannot execute git - so similar error, the "missing directory" ist not mentioned here
    – Pratched
    Commented Jun 15, 2019 at 1:25
  • would root password reset be worth a try?
    – Pratched
    Commented Jun 15, 2019 at 1:26

1 Answer 1

1

Solved only with rescue mode:

  • boot into "rescue mode" - probably available at most VPS
  • mount appropiate drive
  • nano /path/to/mounted/drive/etc/passwd
  • change root entry to root:x:0:0:root:/root:/bin/bash
  • save, exit and reboot without rescue mode

Different approaches like

user1@hostname: ~$ su -s /bin/sh

or

user1@hostname: ~$ su -s /bin/sh -c /bin/sh

did not work and only replied with the same error message.

I did not find the reason (yet), but based on the comments of @doneal24 I regained control over my system. If i can clearify the reason, I will provide the details - see edit below.

REPRODUCING: I (accidentally) found out how I changed the root shell. According to this from ProGit, I thought chsh -s $(command -v git-shell) <user> is enabling the git-shell for input. But inserting git for <user> changes the shell for root.

root@hostname ~ # chsh -s $(git init ./project1.git git-shell) git
usage: git init [-q | --quiet] [--bare] [--template=<template-directory>]             [--shared[=<permissions>]] [<directory>]
chsh: Warning: git does not exist
root@hostname ~ #

I probably misinterpreted the information on ProGit, because this seems a lot like what I wrote under EDIT.

EDIT1: See below on how it actually will be changed.

root@hostname ~# chsh root -s git
chsh: Warning: git does not exist
root@hostname ~#

changed the entry to

root@hostname~ # cat /etc/passwd | grep root
root:x:0:0:root:/root:git
root@hostname~ #

which is curious, as something like

root@hostname ~# chsh root -s /bin/bash
Password:
chsh: PAM: Authentication failure
root@hostname ~#

is not working.

You must log in to answer this question.

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