How can I create a new user then SSH into the box under that user?

I ran:

useradd marco -d /home/marco -p WuUfhRdt4B

Then I added to /etc/ssh/sshd_config:

AllowUsers root marco

Then restarted ssh:

/etc/init.d/ssh restart

I can't login. What did I miss?

** Running Debian.

link|improve this question

70% accept rate
3  
Probably more appropriate for serverfault.com – David Smith Mar 30 '10 at 3:41
Aside from being related to SSH, I don't think it's server specific in any other way. – Marco Mar 30 '10 at 3:46
1  
Whether it's server related or not is besides the point - it's not a programming question – pygorex1 Mar 30 '10 at 4:01
feedback

migrated from stackoverflow.com Mar 30 '10 at 4:22

This question came from our site for professional and enthusiast programmers.

2 Answers

The first thing I see is that you didn't specifically add a shell, you can ensure that the users shell is correct by running as root:

chsh -s `which bash` marco

The other thing to ensure is that the home directory was created by the useradd script.

ls -al /home/marco/

If it was not created you'll need to create it and change the ownership to the correct user:

mkdir /home/marco
cp -a /etc/skel/.[a-z]* /home/marco
chown -R marco.marco /home/marco

I would also make sure that your password was correctly placed in /etc/shadow as I never trust it from the command line:

passwd marco

And enter the password for marco (BTW, it's a really really bad idea to put a password anywhere but in a password field that is not shown. History files are extremely easy to read, as is serverfault :) Make sure you change marcos password is all I'm saying)

If you still can't login check /var/log/auth, /var/log/messages, /var/log/secure etc for sshd entries, it should give you a pretty good idea as to what is failing.

link|improve this answer
You might also want to use the "-v" flag with ssh, to see more verbose output, e.g. "ssh -vv marco@<host>". – wolfgangsz Mar 30 '10 at 9:24
feedback

In your example, is WuUfhRdt4B meant to be the user's password? That won't work because the argument to useradd -p is (according to the man page) "the encrypted password, as returned by crypt(3)." You probably want to use adduser anyway, since it's a lot more intuitive than useradd. Try this:

adduser marco

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.