LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 04-27-2012, 09:12 AM   #1
Mad-Halfling
LQ Newbie
 
Registered: Apr 2012
Posts: 23

Rep: Reputation: Disabled
Using a public SSH key on more than one user


Hi, I've got a MythBuntu media server with my login on it and ssh keys set up, so I can log in from both of my laptops without having to enter a password. I now want to set up a user for my brother (user = dave) and I also want to be able to login from my user to this login to test the security setup.
I copied over my public key file and concatenated it to the /home/dave/.ssh/authorized_keys2 file (I had all sorts of fun and games getting SSH set up initially, so I can't remember if that is ..._keys2 because of something I changed, but it's in the sshd_config as that, and in my home .ssh directory it's also ..._keys2) but I still get a password challenge when I try to ssh -p <fw port> dave@myserver. I then copied over my authorized_key2 file into /home/dave/.ssh but this also doesn't work.
Any ideas why this would be - there isn't any issue in copying the same public key over to multiple users within one computer, is there? If I set up a password for that user I can login ok, so it doesn't seem to be a password expiry issue, as far as I can see. I've also grepped my /etc/ssh/sshd_config with my username and can't find any entries there, so I don't think it's anything in there.
Cheers MH
 
Old 04-27-2012, 09:25 AM   #2
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
Welcome to LQ Security!

Quote:
I copied over my public key file and concatenated it to the /home/dave/.ssh/authorized_keys2.....
You need to copy the public key on to the server and place it in the authorized keys file there. As you are already using this from your PC, there is no need to do this step. The private key needs to go into the .ssh folder of the user that will be logging into the server as id_rsa. From the description, it sounds like you may have the public and private keys backwards.
 
Old 04-27-2012, 09:48 AM   #3
Mad-Halfling
LQ Newbie
 
Registered: Apr 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
You mean the rsa_id.pub file, yes? That's the file I copied and concatenated to the auth..._keys2 file. AFAIK that's the original file I copied over on my user, and either way if I copy my auth..._keys2 file from my user's home .ssh on the server into the ~/dave/.ssh that should be ok, yes? Just to clarify, when I was talking about copying the auth..._keys2 file from one user's home to the other, I was referring to the files in the home directories on the server rather than copying the auth..._keys2 file from the client to the server.

As an example, if I have users foo and bar and I am set up to ssh-key login as user foo
ssh foo@servername
and then I
cp /home/foo/.ssh/authorised_key2 /home/bar/.ssh/authorised_key2
then I should be able to ssh-key login as bar, yes?
ssh bar@servername
and it will use my key for both users?
 
Old 04-27-2012, 10:18 AM   #4
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
I think you have it backwards. When you create the key pair you get two files, id_rsa (private) and id_rsa.pub (public). Authorized keys, to which the public key gets copied / appended goes on the SERVER, not the users. The private key goes with the user. See this link for an example.

Using your example, you would:
Code:
cp /home/foo/.ssh/id_rsa /home/bar/.ssh/id_rsa
Now both users, foo and bar can log into the same server with the same key.

I think you would be better off to generate a unique keypair on your brother's machine and just append that public key to the authorized keys file on the server. The server's authorized key file should have both public keys listed in it, one per line. That way you will both be able to access the server.
 
Old 04-27-2012, 10:27 AM   #5
Mad-Halfling
LQ Newbie
 
Registered: Apr 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
Sorry, I don't think I explained myself clearly enough.
Users foo and bar are both on the server.
I have user foo on my own systems, and from there I want to be able to log onto the server, using the ssh-key, as both user foo and user bar, so I can check everything works ok for the bar user before I set my brother up on it. Once I was happy I was going to get him to send me his public ssh key and import it into user bar, retaining my own ability to log into the server as both foo and bar.
That changes things, regarding your answer, doesn't it?
Apologies that I wasn't clear enough in mt original question.

Recently I've imported ssh keys from user backuppc on my backup server into my laptop's root user so I can remotely backup the system, so I know the users don't have to be the same on the local and remote servers, but I was wondering if there were any issues importing a single user's public key into multiple users on a target server.

Thanks - MH

Last edited by Mad-Halfling; 04-27-2012 at 10:28 AM.
 
Old 04-27-2012, 10:29 AM   #6
roger_heslop
Member
 
Registered: Oct 2009
Location: Leander, TX
Distribution: Fedora 20
Posts: 97

Rep: Reputation: 35
You may need openssh-clients installed to do this, but I find the easiest way is 'ssh-copy-id name@[fqdn_or_ip]' works best. Just build out your key (ssh-keygen -t rsa) then use the previous command to copy to the profile you need.
 
Old 04-27-2012, 10:46 AM   #7
Mad-Halfling
LQ Newbie
 
Registered: Apr 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
I did try using ssh-copy-id but I'm away from home ATM and that doesn't seem to accept ports - I checked the man entry and it only seems to access the -i parameter, but I tried -p anyway, plus it doesn't seem to accept user@machine:port

--edit-- disabled smiles for the :p display

Last edited by Mad-Halfling; 04-27-2012 at 11:24 AM.
 
Old 04-27-2012, 01:17 PM   #8
Mad-Halfling
LQ Newbie
 
Registered: Apr 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
Now I'm home I tried the ssh-copy-id, but it didn't work - it's probably something I've done, what are the basic, user-level things I need to check that might stop a user logging on with ssh keys (but would still allow the password login)?
 
Old 04-27-2012, 03:23 PM   #9
kfritz
Member
 
Registered: Aug 2006
Distribution: Slackware, OpenBSD, CentOS, Ubuntu
Posts: 99

Rep: Reputation: 31
Check the permissions on ~/.ssh directory and ~/.ssh/authorized_keys. sshd is quite fiddly about permissions and you may need to "chmod go-wx" them and make sure they're owned by the user. Look at the man page for sshd, in the FILES section for more details.

Last edited by kfritz; 04-27-2012 at 03:27 PM. Reason: Added "owned by user"
 
Old 04-30-2012, 12:01 PM   #10
Mad-Halfling
LQ Newbie
 
Registered: Apr 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
I did have a look at those - as far as I can see they're the same (apart from, for his user) as my user's file permissions that work ok:-

drwx------ 2 dave dave 4096 Apr 27 18:47 /home/dave/.ssh

and

-rw------- 1 dave dave 395 Apr 27 18:46 authorized_keys2
-rw-r-xr-x 1 dave dave 789 Apr 27 14:45 authorized_keys2.old
-rw------- 1 dave dave 1679 Apr 27 14:14 id_rsa
-rw-r--r-- 1 dave dave 396 Apr 27 14:14 id_rsa.pub

Should these be ok - as I said if you change the user and group names, my .ssh directory and its contents for those files are the same.

The only thing that obviously sticks out is I have a known_host file in my .ssh directory, but I'm guessing that's outgoing ssh hosts, rather that incoming ones?

Last edited by Mad-Halfling; 04-30-2012 at 12:06 PM.
 
Old 04-30-2012, 03:09 PM   #11
kfritz
Member
 
Registered: Aug 2006
Distribution: Slackware, OpenBSD, CentOS, Ubuntu
Posts: 99

Rep: Reputation: 31
What are the permissions on /home/dave? Does sshd log anything into /var/log/messages?

For example, if I have an account "guest" with the following:

drwxrwx--x 4 guest users 4096 Jul 27 2011 /home/guest/

In /var/log/messages, it has this when I try to use a key:

Apr 30 13:03:00 trix sshd[2288]: Authentication refused: bad ownership or modes for directory /home/guest
 
Old 04-30-2012, 09:21 PM   #12
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Here is my "cheat sheet" for setting up ssh:
  1. ssh-keygen -t rsa ... follow prompts.
  2. In Macintosh OS/X there is an ssh-add -K command to add a public-key to that system's ssh-agent keyring, along with passwords.
  3. On the client (this and all remaining steps): mkdir ~/.ssh
  4. chmod 700 ~/.ssh
  5. touch ~/.ssh/authorized_keys
  6. chmod 600 ~/.ssh/authorized_keys
  7. cat keyfile_name >> ~/.ssh/authorized_keys [i](note use of two ">"s)

The strongest thing to do would be to, first on your account, perform the ssh-keygen step to generate your public key, encrypting that with a password. Then, have your brother do the same. (Both of you review the ssh-agent functionality on your systems.) Next, each of you supplies the public key (suffix .pub) for the procedure described above.

I think that it's a good idea to have separate keys, one for each user, and for each person to individually password-protect (encrypt) their own key without revealing it to anyone ... especially one's "bratty brother!"

The whole point of an ssh digital key is to create a unique and individually-manageable identity for one person. I would not "share a key" among more than one user.
 
Old 05-01-2012, 04:50 PM   #13
Mad-Halfling
LQ Newbie
 
Registered: Apr 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
We are generating our own keys and keeping them private - I just wanted to also set up my key on my brother's user so I could check his security was all ok and remote login to his user directly. I removed the existing .ssh directory and followed those steps but it still gives me the password challenge when I try to log in as my brother. Interestingly, in /var/log/auth.log I have this error that occurs when I try to get in:-
reverse mapping checking getaddrinfo for host86 [X.X.X.X] failed - POSSIBLE BREAK-IN ATTEMPT!
X.X.X.X is my ip (I did check to make sure it wasn't a legitimate hacking warning) so I'm guessing that's what's causing the problem. Any idea why it would object to my login on my brother's user, but I can still log into my user ok using the same key - or am I labouring under the misapprehension that I can install the same public key on two different users on the same system? I'm still waiting for my brother to send me his public key to see if his works ok.

Last edited by Mad-Halfling; 05-01-2012 at 04:59 PM.
 
Old 05-01-2012, 05:31 PM   #14
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
The ssh configuration file must be set up to allow rsa-based access and to prohibit password authentication.

Otherwise, ssh has the very annoying habit of starting with the strongest authentication method, then stair-stepping down to the least strong method, and accepting any one that works!

("Oh, my. It seems that you don't seem to know the combination to the impregnable steel door. Would you like to please come in through the open window, instead?")
 
Old 05-01-2012, 06:31 PM   #15
Mad-Halfling
LQ Newbie
 
Registered: Apr 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
I assume you mean the server's ssh configuration, yes? That public key I've imported to my brother's account works fine on my account on that same server, so as far as I can see the server is set up ok? As I said, is the ssh server objecting to that same public key being used on two different users on the same server? I've also, for the moment, left password authentication turned on as I need to log in from other systems, for the moment, but I'll turn it off at some point soon.

Last edited by Mad-Halfling; 05-01-2012 at 06:43 PM.
 
  


Reply



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
open-ssh vs. commercial ssh (tru64), public-key auth not possible? cf050 Linux - Networking 8 03-28-2012 11:15 AM
SSH skips public key authentication for a key, but works with another key simopal6 Linux - General 1 07-06-2011 08:33 AM
[SOLVED] ssh public key login doesn't work as root user confconf Fedora 6 04-06-2011 03:08 PM
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
ssh using public key jkmartha Linux - Networking 1 05-04-2005 02:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 12:24 AM.

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