1

I created a user with root access

useradd -ou 0 -g 0 myuser -p [12345]

when I try to su to the new user, I get:

: No such file or directory

when I want to connect as that user via ssh, I get:

Permission denied, please try again.

So, I checked /etc/passwd:

myuser:x:0:0::/home/myuser:/bin/bash

To test it, I created another user without root access and it worked very well.

I also added this line to /etc/sudoers but it still doesn't work:

root ALL=(ALL) ALL
myuser ALL=(ALL) ALL

I then changed PermitRootLogin in sshd_config but still no luck :(

How can I create a user with root access and ssh into my machine as that user?

4

Usually on Linux there is only one user root, and on Ubuntu it is deactivated. Instead it is a better idea to add all users that should have administrative privilieges to the group sudo by executing

adduser username sudo

as root. That allows them to execute commands as root by typing

sudo command

and get a root shell by

sudo -i

On top op that, you don't have to enable root login for ssh that way.

The home directory probably wasn't created because you added a user with an id (0) that already existed. Avoid setting the userid and groupid manually.


Step-by-Step how-to create an admin user:

  1. sudo adduser username
  2. sudo adduser username sudo
9
  • thanks for your reply , first how to enable root login for ssh? second I want to create an user with root access why I can't ??? – Freeman Jun 21 '15 at 9:43
  • Have you set a password for root? Afaik there's no way to create a second root user, but the approach with groups I described is even better imho. – luckyrumo Jun 21 '15 at 9:47
  • yeah I set that, actually I create an user with adm group but again I can't login to the new user ! why ? – Freeman Jun 21 '15 at 9:49
  • did you add the user like I write above (I edited the answer)? – luckyrumo Jun 21 '15 at 9:55
  • I done that yes, in step 2, when I checked the passwd it didn't change so I open the passwd manually and change group to adm (4) but it didn't work again – Freeman Jun 21 '15 at 10:02
2

The first error is because you created a user whose home directory doesn't exist. This is one of the reasons why you should always use adduser instead of useradd. As explained in man useradd:

   useradd is a low level utility for adding users. On Debian,
   administrators should usually use adduser(8) instead.

One of the features of adduser is that it automatically creates the home directory for you. So, what you wanted to run was:

    sudo adduser --gid 0 --uid 0 username

The next issue is that you have to allow root login. Edit /etc/ssh/sshd_config and change

PermitRootLogin no

to

PermitRootLogin yes

Then, restart the ssh server:

sudo service ssh restart
2
  • Allowing remote root logins is a bad idea. luckyromo's answer is more secure. Ideally, you don't want to allow password login, either, instead using RSA keys. There are bots out there brute-forcing root logins on any ssh server they can find. – jpaugh Sep 15 '16 at 16:12
  • Granted, this answer is precisely what the OP was asking for. – jpaugh Sep 15 '16 at 16:13
0

After hours it's finally done! I just create new user like this :

useradd -ou 0 myuser -p [#hash-password]

and then I changed PermitRootLogin yes in this path : /etc/ssh/sshd_config

easy as pie :)

1
  • This will still give you the error about no home directory. – terdon Jun 21 '15 at 13:46

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.