SSH login using public key failed

localhostrsassh

On localhost running sshd service. Created two pairs of rsa keys for root and user1 using ssh-keygen. Copied from root/.ssh/id_rsa.pub to user1/.ssh/id_rsa.pub. Changed permissions to 600. Tried ssh -l user1 localhost and ssh -l root localhost but both failed with Permission denied (publickey,keyboard-interactive).. Do I have to copy public key to ~/.ssh folder for both users? What is wrong with configuration? Why I cannot connect to localhost?

File /etc/ssh/sshd_config:

RSAAuthentication yes
PubkeyAuthentication yes
PasswordAuthentication yes
UsePAM no
AllowUsers user1 root
PermitRootLogin yes

In file /etc/ssh/ssh_config is uncommented lines:

   RSAAuthentication yes
   PasswordAuthentication no
   ForwardX11 no
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials no
   PubkeyAuthentication yes

EDIT 1

I am trying to connect to localhost. I have to be able to login to user1 using only public key while possible to login as root with public key and/or password.


EDIT 2

I copied cp ~/.ssh/id_rsa.pub /home/user1/.ssh/authorized_keys. Changed permissions chmod -R 700 ~/.ssh and chmod -R 700 /home/user1/.ssh. Restarted sshd 'service ssh restart'. But it seems not working.


EDIT 4

root@ubuntu:~# ssh-copy-id user1@localhost
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is 34:29:b6:1b:fe:84:eb:82:85:77:87:f6:25:39:61:5a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
Permission denied (publickey,keyboard-interactive).

root@ubuntu:~# ssh-copy-id root@localhost
Permission denied (publickey,keyboard-interactive).

Log:

# tail /var/log/auth.log

... ubuntu sshd[8476]: User root not allowed because account is locked

A good SSH troubleshot article: Problems and Solutions

Best Answer

I ran into this issue when i tried to login to an account that has no password, even though i use SSH key pair authentication and have password login turned off. The solution was to set a password using my root account:

passwd user1
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully