2

I have a VM here running Ubuntu 14.04.2 LTS (GNU/Linux 3.16.0-30-generic x86_64) and we was given access to it through a user let's call it userx so every time we login to this VM through ssh like:

ssh -p 22 userx@1.2.3.4

It automatically changes the user to root so it enters in the machine as:

root@machinename:~#

And if I run the pwd it shows that I am in the userx folder /home/userx. And if I run su userx it log in as root again.

So how do I change that so when logging in with userx I actually get logged in as userx like userx@machinename:~# ?

Edit as requested in comments:

root@machinename:~# grep userx /etc/passwd
userx:x:0:0:somename,,,:/home/userx:/bin/bash

I changed the value of somename to keep the privacy. I take that it is the group right?

root@machinename:~# ls -l /home
total 4
drwxr-xr-x 10 1000 userx 4096 Nov  8 11:10 userx
  • 1
    Can you post the output of grep userx /etc/passwd and ls -l /home – Panther Nov 8 '17 at 14:30
  • @Panther done as requested. Thanks for the help – Jorge Campos Nov 8 '17 at 14:36
1

The problem is "userx" is root. Root is identified by UID of 0 as shown in /etc/passwd

userx:x:0:0:somename,,,:/home/userx:/bin/bash

See https://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/ for understanding the output.

So, what you can do, although it is moderately invasive, do all this from a root shell !!!

In your case you will need to manually edit etc/passwd and /etc/groups

nano /etc/passwd

edit the userx line

userx:x:1000:1000:somename,,,:/home/userx:/bin/bash

Then /etc/groups

At least

userx:x:1000:

While you are there, you can add userx as needed to other groups. Add userx at the end of the line, comma separated if needed (posted this list from a desktop install). You may add yourself to other groups as needed (www-data ?)

adm:x:4:syslog,userx
cdrom:x:24:userx
sudo:x:27:userx
dip:x:30:userx
plugdev:x:46:userx
lpadmin:x:118:userx
userx:x:1000:
sambashare:x:128:userx

Then setup ssh (if needed)

cp -R /root/.ssh /home/userx
chown -R userx:userx /home/userx

BEFORE YOU EXIT THE ROOT SHELL , from your client, test ssh and sudo

ssh userx@1.2.3.4 #you do not need to specify the port if it is the default

Now assuming you can long in via ssh, test sudo

sudo -i

As long as you can log in via ssh and obtain a root shell you are good to go.

If you have a problem you will need to post back, we may need to configure ssh and / or sudo

  • When I run usermod -l root userx it says usermod: user 'root' already exists ignore and keep going or do I have to do something else? – Jorge Campos Nov 8 '17 at 15:00
  • I executed the command you updated usermod -u 1000 userx and it returns usermod: user userx is currently used by process 1 is it a problem? – Jorge Campos Nov 8 '17 at 15:06
  • I will check the ssh and sudo of course, when I get to that part :) – Jorge Campos Nov 8 '17 at 15:07
  • Yes, Just did it, and tested every thing and it is working fine!! Thank you!! I will mark your answer as accepted :) – Jorge Campos Nov 8 '17 at 15:44
1

You user userx has the ID and Group ID 0, that means it become automatically a root user. You may have to create a user with different ID, best practice are starting from 1000 as previous ID are supposed to be reserved for the system accounts.

userx:x:0:0:somename,,,:/home/userx:/bin/bash

The syntax to change a user ID is:

usermod -u UID userx

By example

usermod -u 1000 userx

And to change the primary group

usermod -g groupx userx

By example, for having the user to be member of a group with the same same (default behavior in Linux).

groupadd userx # < Command useless for you as group userx already exists
usermod -g userx userx
  • Yep, that's an old trick to backdoor systems. Used to change the nobody built-in user to a login shell and 0:0 for an obvious but not TOO obvious backdoor people usually overlook. – RobotHumans Nov 8 '17 at 14:56
  • great answer, but we still need to make sure both ssh and sudo are working. – Panther Nov 8 '17 at 15:04
  • Hi olivierb2, thanks for your answer and explanation. I will upvote it. I will try the Panther's answer though, it is more complete (ssh/sudo test) – Jorge Campos Nov 8 '17 at 15:10
  • Did not work (read comments above) "usermod -u 1000 userx and it returns usermod: user userx is currently used by process 1" so will probably not work with 'su root' or from recovery mode due to userx == root == UID 0 but I am not sure. – Panther Nov 8 '17 at 15:21
  • You should do my command by connecting with root account directly from the VM console (not over ssh). If it's not feasible, you may have temporarily allow root from ssh and enable root password. – ob2 Nov 8 '17 at 15:25

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.