37

I have an Ubuntu server setup using amazon ec2 instance. I need to connect my desktop (which is also a ubuntu machine) to the ubuntu server using SSH.

I have installed open-ssh in ubuntu server. I need all systems of my network to connect the ubuntu server using SSH (no need to connect through pem or pub keys).

Hence opened SSH port 22 for my static IP in security groups (AWS).

My SSHD-CONFIG file is:

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

Through webmin (Command shell), I have created a new user named 'senthil' and added this new user to 'sudo' group.

sudo adduser -y senthil
sudo adduser senthil sudo

I tried to login using this new user 'senthil' in 'webmin'. I was able to login successfully.

When I tried to connect ubuntu server from my terminal through SSH,

ssh senthil@SERVER_IP

It asked me to enter password. After the password entry, it displayed:

Permission denied, please try again.

On some research I realized that, I need to monitor my server's auth log for this. I got the following error in my auth log (/var/log/auth.log)

Jul  2 09:38:07 ip-192-xx-xx-xxx sshd[3037]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=MY_CLIENT_IP  user=senthil
Jul  2 09:38:09 ip-192-xx-xx-xxx sshd[3037]: Failed password for senthil from MY_CLIENT_IP port 39116 ssh2

When I tried to debug using:

ssh -v senthil@SERVER_IP


    OpenSSH_5.9p1 Debian-5ubuntu1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to SERVER_IP [SERVER_IP] port 22.
debug1: Connection established.
debug1: identity file {MY-WORKSPACE}/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file {MY-WORKSPACE}/.ssh/id_rsa-cert type -1
debug1: identity file {MY-WORKSPACE}/.ssh/id_dsa type -1
debug1: identity file {MY-WORKSPACE}/.ssh/id_dsa-cert type -1
debug1: identity file {MY-WORKSPACE}/.ssh/id_ecdsa type -1
debug1: identity file {MY-WORKSPACE}/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.8p1 Debian-7ubuntu1
debug1: match: OpenSSH_5.8p1 Debian-7ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA {SERVER_HOST_KEY}
debug1: Host 'SERVER_IP' is known and matches the ECDSA host key.
debug1: Found key in {MY-WORKSPACE}/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: password
debug1: Next authentication method: password
senthil@SERVER_IP's password: 
debug1: Authentications that can continue: password
Permission denied, please try again.
senthil@SERVER_IP's password: 

For password, I have entered the same value which I normally use for 'ubuntu' user.

Can anyone please guide me where the issue is and suggest some solution for this issue?

3
  • You did set the password for the ubuntu user? And you're sure you're typing it correctly? Also include the output of id ubuntu run from your server in your question. Did you lock the account perhaps? Consider including the output of grep ^ubuntu /etc/passwd /etc/shadow (and change the encrypted password only in the middle of the string).
    – gertvdijk
    Jul 2, 2013 at 11:19
  • Actually I haven't created any seperate user for SSH. I have used the user which I normally use for server login. The output of grep ^ubuntu /etc/passwd /etc/shadow is: /etc/passwd:ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/bin/bash /etc/shadow:ubuntu:!$6$rWDSGDSGhv$WDFDASGFDAG.Pz0ob54/epaDSGDSGQKnKqQMFG..OieFiLUndF6KnSDGHDSGHmTMjAGHDSH214I7FHSi1:15347:0:99999:7::: Jul 2, 2013 at 11:22
  • Thanks again for your clear response.. If I need to create separate user for SSH and add that to some SSH config, can you please give me some steps for that. Jul 2, 2013 at 11:23

17 Answers 17

15

You've locked the account.

From the manpage of usermod(8):

-L, --lock
           Lock a user's password. This puts a '!' in front of the encrypted password,
           effectively disabling the password.

Now look at your shadow line:

ubuntu:!$6$rWDSG...HSi1:15347:0:99999:7:::

Unlock it:

usermod -U ubuntu

Important note! If this user is preinstalled on the system it may be locked for a reason (security reasons), but I cannot decide that for you since this isn't a regular Ubuntu install apparently.


If the above makes you feel uncomfortable, you could create a separate user:

sudo adduser username

and answer the questions. You should be able to login just fine. Also make it able to become root (use sudo) by adding it to the sudo group:

sudo adduser username sudo

In case you need to switch to the ubuntu user on the command line, you'll have to use your elevated privileges, because you can't provide credentials for the same reason as why you can't log in using SSH. Now, log in using SSH as username, and run this to become ubuntu:

sudo su -l ubuntu

For security reasons I would not advise to use root to log in directly.

9
  • I feel the user 'ubuntu' is locked for security reasons. Or to avoid this confusion, I have also tried to login using my root user account.. I am still getting the same error in terminal and auth.log file. Jul 2, 2013 at 11:29
  • You mean the root account? That account doesn't have a password and is locked by default. Have you enabled it?
    – Alaa Ali
    Jul 2, 2013 at 11:31
  • @Kamal I've updated my answer to include how to do that.
    – gertvdijk
    Jul 2, 2013 at 11:36
  • Thanks gertvdijk. I will try this now. I have also editted my question and updated the output of ssh -v ubuntu@SERVER_IP Jul 2, 2013 at 11:40
  • @Alaa: No.. I haven't enabled it. Just tried to login using root.. Currently I am using the user: 'ubuntu' for login (in webmin) Jul 2, 2013 at 11:43
12

This is not exact answer for this question. But In my case, there was redundant lines. (there were same line twice)

PermitRootLogin yes

and also

AllowUsers otheruser

You should add 'root' user to this line or comment this line.

And restart ssh service sshd restart

0
8

I have the same problem and it take for me many hours .

However, i note that it is a wrong password because of differrence between keyboard layout of server snd client :

In Server, i thought that i set password : WEwd@ds And , i note that @ is " in the server keyboard layout.

So the right password is : WEwd"ds


Thus, you need to check :

Server keyboard layout [vs] Workstation keyboard layout

2
  • 1
    This was it. My Raspbian system reverts to the GB keyboard at every reboot and I have to go into Preferences->Keyboard and Mouse to reset it to US. Thanks for having this answer waiting for me to need it January 2018.
    – SDsolar
    Jan 6, 2018 at 21:19
  • I had the opposite problem - Windows changed my keyboard layout for some reason, and so I was giving the wrong password through my SSH client.
    – mwfearnley
    Dec 31, 2018 at 12:40
5

In my case,

I closed Windows PowerShell

and try it with Git Bash

Now It works fine.

And then I throw PowerShell away.

2

I found where the issue is and fixed.

I have created a new user (named: senthil) and just used it for SSH. In Ubuntu, I feel that when we create a new user, by default the root user's password will be assigned to the new user. Even then, reset and assign some new password to the newly created users.

Once after the user password reset and making the following changes in sshd_config, now I am able to connect all my systems (from my network) to remote server.

Please Note: I have switched off all SSH authentications (like RSAAuthentication, PubkeyAuthentication and KerberosAuthentication).. I have turned on only the PasswordAuthentication.

Thank You.

5
  • "I feel that when we create a new user, by default the root user's password will be assigned to the new user." <-- No, you are asked to set a password using adduser. Did you use useradd instead?
    – gertvdijk
    Jul 4, 2013 at 19:14
  • I have used the following two commands: "sudo adduser -y senthil" and "sudo adduser senthil sudo". May be as I have created users using webmin commandline, it haven't asked me to enter password during user creation Jul 5, 2013 at 6:49
  • gertvdijk, consider that I am having only webmin access for a server. In webmin command line, GUI prompt or the step by step installation is not possible. So I feel that in webmin command line, it haven't asked me to enter password. In such cases what can I do? Is there any other command, other than "sudo adduser -y senthil" such that in ONE COMMAND I will create and assign passwords to users? sorry for the lengthy question. Jul 5, 2013 at 6:54
  • But you have console access on an EC2, right? Of course, running these commands via Webmin is VERY limited. Sorry that I wasn't explicit on running this in the console rather than Webmin (this really limits your options/capabilities).
    – gertvdijk
    Jul 5, 2013 at 9:14
  • You meant that, you just change the password of that user and everything OK? I have the same problem. In my case all the users include root get that error?!
    – shgnInc
    Dec 1, 2013 at 15:53
2

For me, it was as easy as setting

PermitRootLogin no

to:

PermitRootLogin yes

Don't forget

systemctl restart sshd
2

This worked for me, follow 2 simple steps:

  1. Change root password
  2. Make changes in etc/ssh/sshd_config file

If 1st step works, no need to do 2nd step.

1st Step explanation:

In your terminal type, sudo passwd root, after changing the password try ssh root@IP if it works, great. If it does not. Follow 2nd step.

2nd Step explanation:

  1. In your terminal type, sudo gedit etc/ssh/sshd_config
  2. Scroll to # Authentication:

Before it will be like this:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

Make it to :

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

Save it and use ssh restart command systemctl restart sshd

Now try ssh root@IP

Hope this works. Thanks.

1
  • Thanks! SSH root login with password stopped to work after I generated ssh key for the root user. I tried to change sshd_config but it didn't help, only resetting root password did. It's strange...
    – d9k
    Jul 19, 2022 at 15:24
1

I have a solution for you In your sshd_config file you add this following line in the end of the file:

AllowUsers senthil

This line will allow your server can connect to user's name: senthil. Another user will be denied. After that go to your terminal on your sever type this command:

ssh senthil@yourhostname

Done! Good luck to you More information you can come here and see. http://www.htpcbeginner.com/install-ssh-server-on-ubuntu-1204/

1

In my case, this solved the issue: In the server running openssh-server I changed the user (myserverusername) and root (root) password to the one I was previously using:

sudo passwd myserverusername

and

sudo passwd root

Then reboot the ssh server daemon:

sudo service ssh restart

It is strange because I dont recall changing passwords

0

For the desperate, double check your /etc/hosts file to make sure you aren't tricking your computer into thinking a certain host name has a different IP than it really. >.<

0

Check sshd access List for Allowed Users(config file)

  1. cat /etc/ssh/sshd_config
  2. AllowUsers

should not be set, it should be commented out # as shown in example below.

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       ForceCommand cvs server
Ciphers aes128-ctr,aes192-ctr,aes256-ctr
ClientAliveInterval 432000
ClientAliveCountMax 0
#AllowUsers TestUser
0

I have seen many answers to this questions. I too faced the problem. My case was my ssh connection were working before then, I changed to windows 10 auto upgraded. Did not work on Ubuntu on my desktop for long.

Not sure what was the problem. I checked \etc\hosts file, sshd_config file everything looked alright. Then I decided to check my antivirus settings - bingo that is the problem!

The putty application was on the denied list. So enabled it... then log in successfully. A big scream!

0

Whenever I got struck,this command gives me temporary solution, since I am using different username for Ubuntu

chown -R $USER:$USER /var/www
0

I had the exact same error output and in my case the reason was this line in /etc/ssh/sshd_config:

AllowUsers ubuntu root

Naturally, this was denying access to everyone except ubuntu and root users.

The following worked:

  1. Adding new user in the list:

    AllowUsers ubuntu root tempuser1
    
  2. Restarting the sshd:

    sudo service sshd restart
    
0

After implementing everything mentioned above, I finally found that a server reboot works for me.

I am assuming this was cache? But it was weird for me at least.

0
0

Check /etc/ssh/sshd_config by

# cat /etc/ssh/sshd_config 

Find a line starting with AllowUsers and add your username to it like this:

AllowUsers scom omar ahmed root
0

Fault phenomenon

in my case,

  • server using dropbear.
  • client using openssh-client

and the client got this err msg (when connnecting):

Permission denied, please try again


Troubleshooting

but it not always the precise reason.
I check the dropber.log, and found the Source of the problem:

User 'xxx' has invalid shell, rejected


then fixed by chsh -s /bin/ash xxx.




Summary:

Maybe the reasons for failure are different,
But this troubleshooting method may have reference significance.

// if server reject, it may tell more detail in server log than in response to client.

You must log in to answer this question.

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