CentOS Icon CentOS Logo
CentOS Text
   
  
www.centos.org Forum Index
   CentOS 6 - Networking Support
  [SOLVED] Unable to connect with SSH and RSA Key

 

 Bottom   Previous Topic   Next Topic
  •  Rate Thread
      Rate this Thread
      Excellent
      Good
      Average
      Bad
      Terrible
Poster Thread
  •  koshie
      koshie
[SOLVED] Unable to connect with SSH and RSA Key
#1
Newbie
Joined: 2011/5/10
From
Posts: 5
Hello,

I'm trying to setup an automatical connection between both of my servers (Omen & Maelys) using SSH and RSA Key to backup Omen to Maelys. Both using CentOS 6 64 bits.

On Omen I've generated a SSH RSA key whitout password, I've send it with this command :

cat /root/.ssh/id_rsa.pub | ssh -p port user@mydns.tld "cat - >> ~/.ssh/authorized_keys"


Maelys successfuly received this and placed it into ~/.ssh/authorized_keys with my comment "Omen", there is only one entry in this file.

I've edited /etc/ssh/sshd_config on Maelys to have this :

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys


I've restarted sshd and after when I'm trying to connect myself automaticaly from Omen to Maelys I'm asked for password...

I'm sure that's something really stupid but I don't see it.

Hope someone can help me here :), nice Tuesday.

EDIT : I've also restarted sshd on Omen.

Cordially, Koshie
Posted on: 2012/5/1 7:52
Create PDF from Post Print
Top
  •  TrevorH
      TrevorH
Re: Unable to connect with SSH and RSA Key
#2
Moderator
Joined: 2009/9/24
From Brighton, UK
Posts: 6361
Quote:

On Omen I've generated a SSH RSA key whitout password, I've send it with this command :

cat /root/.ssh/id_rsa.pub | ssh -p port user@mydns.tld "cat - >> ~/.ssh/authorized_keys"



Is the 'scp' command broken on your machine? It's much easier than this convoluted workaround and preserves file permissions on the way - which is probably the source of your problems. Try removing the destination file and then running

scp -p -P port /root/.ssh/id_rsa.pub user@mydns.tld:~/.ssh/authorized_keys


Oh, and it's generally not a good idea to share keys between ordinary users and root - better that each user has their own key that lets them in as themselves and then give sudo access to whatever they need to do and nothing else.

Quote:

I've edited /etc/ssh/sshd_config on Maelys to have this :

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys



These are all the default options anyway so this didn't need to be done.

If this still doesn't work then you need to check the rest of the permissions on the destination host files and directories. The user's ~/.ssh directory should be chmod 700 and owned by user:user. The authorized_keys file inside it should be chmod 600 and also be owned user:user. You may also want to run the command

restorecon -R ~user/.ssh


as the root user to restore the correct selinux contexts to the directory and all its files.
_________________
Linux/VoIP Systems Administrator
Posted on: 2012/5/1 8:28
Create PDF from Post Print
Top
  •  koshie
      koshie
Re: Unable to connect with SSH and RSA Key
#3
Newbie
Joined: 2011/5/10
From
Posts: 5
I was not using 'scp' because I has a permission problem (in root !) and I've not solved it, but with your command it works well, maybe the option '-p' resolv it.

I was using root user because I need to backup some directory like /etc or /var and I've thinked that was the best way to do that properly. The goal is to backup somes directory without using a password, automatically with cron. So it's better to give 'sudo' to my user ? It will ask for password if I'm trying to cron an 'rsync' command on directory owned by root ?

This is permission of /home/user/.ssh :
drwxrwxr-x.  2 user user      4096  1 mai   07:54 .ssh

Permission of the content :
-rw-r--r--. 1 user user  386  1 mai   08:17 authorized_keys
-rw-r--r--. 1 user user  426 30 avril 12:24 known_hosts


Finally, I've executate the command :
restorecon -R ~user/.ssh
and cat authorized_keys (there is always the key in it) and it doesn't works, on Omen I'm always asked for password.

I've of course restarted sshd somes times.

Thanks for your reply.
Posted on: 2012/5/1 9:58
Create PDF from Post Print
Top
  •  TrevorH
      TrevorH
Re: Unable to connect with SSH and RSA Key
#4
Moderator
Joined: 2009/9/24
From Brighton, UK
Posts: 6361
Quote:

This is permission of /home/user/.ssh :
drwxrwxr-x.  2 user user      4096  1 mai   07:54 .ssh

Permission of the content :
-rw-r--r--. 1 user user  386  1 mai   08:17 authorized_keys
-rw-r--r--. 1 user user  426 30 avril 12:24 known_hosts



Needs to be 700 on /home/user/.ssh not your current 775. Also authorized_keys needs to be 600 not its current 644.
_________________
Linux/VoIP Systems Administrator
Posted on: 2012/5/1 10:41
Create PDF from Post Print
Top
  •  koshie
      koshie
Re: Unable to connect with SSH and RSA Key
#5
Newbie
Joined: 2011/5/10
From
Posts: 5
It works well, thanks for your help and your rapidity :).

Cordially, Koshie.
Posted on: 2012/5/1 12:06
Create PDF from Post Print
Top
  •  AlanBartlett
      AlanBartlett
Re: [SOLVED] Unable to connect with SSH and RSA Key
#6
Moderator
Joined: 2007/10/22
From ~/Earth/UK/England/Suffolk
Posts: 9138
Thank you for reporting back.

On your behalf (and for posterity) this thread is now marked [SOLVED].
_________________
Alan

100% Unix & Linux. Co-founder of the ELRepo Project.
Posted on: 2012/5/1 23:09
Create PDF from Post Print
Top
 Top   Previous Topic   Next Topic

 


 You cannot start a new topic.
 You can view topic.
 You cannot reply to posts.
 You cannot edit your posts.
 You cannot delete your posts.
 You cannot add new polls.
 You cannot vote in polls.
 You cannot attach files to posts.
 You cannot post without approval.




"Linux" is a registered trademark of Linus Torvalds. | All other trademarks are property of their respective owners. | All other content is Copyright @ 2004-2009 by the CentOS Project or "each individual contributor (forums, comments, etc.) unless otherwise assigned".| Theme based on a theme by 7dana.com