16

I created a new user on ubuntu 10 username: codeuser

There is an existing user called "admin". Now, my problem is that I cannot directly connect to the server using the codeuser credentials. But, I can SSH in through "admin" and then su (change the user to codeuser) and it works. How do I get the shell access to the codeuser user ?

This is the output of my files:

cat /etc/passwd

root:x:0:0:root:/root:/bin/bash
www-data:x:33:33:www-data:/var/www:/bin/bash
admin:x:1000:1000:,,,:/home/admin:/bin/bash
ftp:x:107:65534::/home/ftp:/bin/false
codeuser:x:1004:33::/home/codeuser:/bin/bash


cat /etc/group

root:x:0:
www-data:x:33:
codeuser:x:1005:



iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination          
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:mysql  

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination          

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
Stewie
  • 577
  • 2
  • 7
  • 17
  • 2
    Check /etc/ssh/sshd_config for allowed users list. If it is OK, the problem is more complex. Try to connect as "ssh codeuser@your-server -v" – HUB Apr 01 '11 at 17:08
  • When you ssh in as codeuser what error message is displayed after entering the codeuser credentials ? – user9517 Apr 01 '11 at 17:09
  • @HUB it worked [can you please make it an answer, so I can accept it ?]. Strange, I thought I checked that file. Now, do I have to add a user to that file everytime I create a new user ? Isn't there a automatic script / command ? – Stewie Apr 01 '11 at 17:13

8 Answers8

12

Check /etc/ssh/sshd_config for allowed users list. If it is OK, the problem is more complex. Try to connect as "ssh codeuser@your-server -v"

HUB
  • 6,630
  • 3
  • 23
  • 22
  • 2
    My sshd_config file does not have any users defined, but I can SSH in as root, and user1, but not user2 – wruckie May 21 '18 at 16:34
  • 1
    @wruckie In my case, the shell assigned to the user was not correct. If it is suspected, please try editing `/etc/passwd`. My problem had been solved by changing `/usr/bin/bash` to `/bin/bash`. (cf. [New Users Can't Login via SSH](https://archlinuxarm.org/forum/viewtopic.php?f=57&t=9639)) – ynn Nov 28 '19 at 10:48
5

Stumble to this thread after create a new user and cannot SSH to the new user. I managed to fix it after looked for the group and user of .ssh folder and authorized_keys file. They were set to root:root, because I copied them from other user's folder with sudo.

So I fix it with:

sudo chown new_user:new_user /home/new_user/.ssh/
sudo chown new_user:new_user /home/new_user/.ssh/authorized_keys

Hope this helps

Wild Teddy
  • 151
  • 1
  • 2
5

On Ubuntu 18.04 I had simply neglected to add my client's public key to the authorized keys file (this post got me thinking about the authorized_keys file: https://superuser.com/a/1337741/413936).

chmod 700 ~/.ssh
cd ~/.ssh
touch authorized_keys
chmod 600 authorized_keys

Then add your client's public key to authorized_keys file.

For whatever reason though, I didn't need to add PasswordAuthentication yes to /etc/ssh/sshd_config on Ubuntu 18.04.3 LTS as other people have mentioned. To be clear, mine is commented out like this # PubkeyAuthentication yes and I restarted both ssh and sshd services and was still able to ssh in.

jbobbins
  • 155
  • 1
  • 4
  • That commented out `# PubkeyAuthentication yes` really puzzles me - it's either not mentioned on many Debian 10 security guides, or they recommend uncommenting it, yet it seems **leaving it commented out** still enables login with an SSH key? – Dave Everitt Mar 14 '21 at 17:04
2

Check /var/log/auth.log for any errors. Did you assign codeuser a password using the passwd command?

Pratik Amin
  • 3,303
  • 3
  • 22
  • 19
0

Make sure the public key is correct in this place:

/home/newUsername/.ssh/authorized_keys
0

A quite old post but still valid. Worth checking logs as Marco Ramos mentioned above. In my case with Debian 9 a group must granted with permissions /var/log/auth.log

Nov 23 23:10:46 AreNAS sshd[6765]: User are from 192.168.0.36 not allowed because none of user's groups are listed in AllowGroups
b00lve
  • 1
-1

Try to check /var/log/auth.log for possible error messages.

Also, ask the user to try to login with ssh -v, for more verbose output.

Hope this helps!

Marco Ramos
  • 3,120
  • 23
  • 25
-2

On new Debian installations (may be even other distributions) you have to enable password login. It started to happen recently. AllowUsers won't help you, PermitRootLogin yes won't help you.

Default configuration in /etc/ssh/sshd_config is:

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes

but it won't let you ssh to it with plain text password. You have to uncomment it, restart sshd, insert your ssh key and comment it back or leave it enabled.