LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-31-2020, 06:03 AM   #1
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Rep: Reputation: Disabled
[ssh] RSA key authentication not working


In the server /etc/ssh/ssh_config, I've set
Code:
PasswordAuthentication no
restarted the daemon, and from the host copied a public id_rsa.pub on the server with ssh-copy-id:
Code:
$ ssh-copy-id -i ~/.ssh/id_rsa.pub useronserver@server
The key was copied well and shows exactly the same in userlocalhome/.ssh/id_rsa.pub as in userserverhome/.ssh/authorized_keys. However, the server keeps asking me for a password. Did I miss something?
 
Old 12-31-2020, 06:35 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by thomasbb View Post
In the server /etc/ssh/ssh_config
Shouldn't you be editing /etc/ssh/sshd_config instead?
 
1 members found this post helpful.
Old 12-31-2020, 06:47 AM   #3
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
Shouldn't you be editing /etc/ssh/sshd_config instead?
Apologies, there was a 'd'... Now it says
Code:
Permission denied (publickey).
Does it take another configuration? Maybe it's because my DHCP hasn't any domain name set up and the authorized_keys shows user@name-of-the-local-host?

Last edited by thomasbb; 12-31-2020 at 06:49 AM. Reason: add info
 
Old 12-31-2020, 07:06 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Did you restart the sshd service?
Careful if you aren't 100% sure that Key login works.
You could lock yourself out.
Do you have physical access to the server?

Follow a decent tutorial, e.g. https://wiki.archlinux.org/index.php/Ssh_keys
 
1 members found this post helpful.
Old 12-31-2020, 07:31 AM   #5
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
The server is an old PC I configured as a router and it's by my desk, so I can reconfigure it physically when needed.
The service is restarted but it still doesn't accept my key... Thank you for the link
 
Old 12-31-2020, 07:50 AM   #6
marav
LQ Sage
 
Registered: Sep 2018
Location: Gironde
Distribution: Slackware
Posts: 5,441

Rep: Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189Reputation: 4189
Hi,

Do you have this line in your sshd_config ?
Code:
PubkeyAuthentication yes
 
1 members found this post helpful.
Old 12-31-2020, 08:33 AM   #7
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by marav View Post
Code:
PubkeyAuthentication yes
It was commented but it seems to be the default value. If I uncomment it and restart the service, it still doesn't work. But if I comment the PasswordAuthentication no line, then I can connect with ssh useronserver@IP-of-the-server. The same happens if instead of the IP I use the hostname of the server.

Maybe it takes an SSH agent?
 
Old 12-31-2020, 08:51 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937
You can connect but I assume you need to enter your password.

Make sure the ~/.ssh directory is owned by your user_on_server and has permissions 700 i.e. drwx------
The ~/.ssh/authorized_keys file should also be owned by your user_on_server and have permissions of 600 i.e. -rw-------

Using the ssh -v option shows additional debug messages which might lend a clue to why keys are not working.
 
1 members found this post helpful.
Old 12-31-2020, 09:17 AM   #9
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Using the ssh -v option shows additional debug messages which might lend a clue to why keys are not working.
The client doesn't find my private key:
Code:
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/user/.ssh/id_rsa
debug1: Trying private key: /home/user/.ssh/id_dsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa_sk
debug1: Trying private key: /home/user/.ssh/id_ed25519
debug1: Trying private key: /home/user/.ssh/id_ed25519_sk
debug1: Trying private key: /home/user/.ssh/id_xmss
debug1: Next authentication method: password
It's named id_rsa_router, and I made another one named id_rsa_router_2048 with less encryption. But apparently the client uses none of them... Regarding the access rights, I had checked them
 
Old 12-31-2020, 09:26 AM   #10
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
With the -i option, it all goes well... Thank you for your help
 
Old 12-31-2020, 09:27 AM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937
In that case the key name must be used on the command line via the -i option or you can use a ~/.ssh/config file to automatically use user defined directives.
Code:
Host My_Server
    HostName IP_address or hostname
    User user_on_server
    IdentityFile ~/.ssh/id_rsa_router
To connect to your server just use the Host name

ssh My_Server
 
1 members found this post helpful.
Old 12-31-2020, 09:40 AM   #12
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
In that case the key name must be used on the command line via the -i option or you can use a ~/.ssh/config file to automatically use user defined directives.
Code:
Host My_Server
    HostName IP_address or hostname
    User user_on_server
    IdentityFile ~/.ssh/id_rsa_router
To connect to your server just use the Host name

ssh My_Server
Perfect. Thank you for the ~/.ssh/config trick
 
  


Reply

Tags
ssh access using key, ssh authorization



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
RSA SecurID: RSA Web Agent, integration of RSA auth page Linux_Kidd General 1 08-28-2013 05:59 PM
[SOLVED] trouble with RSA key authentication and ssh selahlynch Linux - Networking 7 02-02-2011 08:06 AM
Putty/SSH login failed when using RSA public key: 'Server refused our key' itsecx@gmail.com Linux - Server 10 10-04-2010 01:19 PM
failed ssh RSA key authentication jdarren Linux - Networking 15 07-06-2008 10:25 AM
RSA Key Authentication with SSH fail with no reply for publickey powah Linux - Security 2 11-18-2006 12:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration