New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
How to have 2 ssh keys in one Linux account?
I use ubuntu at home and I have ssh key to connect to my personal servers. But currently, I also need to connect to office servers, but I have a different generated ssh key for that also.
The only method I know for know, is to add another user on my desktop and switch user if I want to connect to my personal, or to office servers. Which is inconvenient.
Any ideas?
Comments
Its late, and I may have read that in reverse but wouldn't http://serverfault.com/a/221766 allow this?
Lookup "ssh config file". If I understood your question correctly, that should do it.
You could either create a bash alias i.e.
Or use the ssh/config file to specify the key to be used with a specific host, i.e.
The simple thing to have done is to have given the office servers the same public key as you were already using for the personal servers rather than generating a new key. It adds no security to have multiple ssh keys under the same account in linux (unless some of them are password protected, in which case your inconvenience goes up tenfold however you slice it or dice it).
You can use an unlimited number of ssh keys per user.
On the same account:
Either specify the key for each ssh or scp command:
For Server 1:
For Server 2:
Alternately, create ~/.ssh/config with the following entries:
Now, you can connect with:
$ssh pvt
and$ssh work
You can even do:
scp myfile pvt:/root/someplace/
I use Droidzone's solution.
I'm using royal tsx (royal ts for windows), it can manage your different ssh keys.
thank you all for the solution. It seems my understanding is very shallow. Thanks for pointing that it can be solved using .ssh/config
Digitalocean 'library' has a nice howto on .ssh/config organization.
Once you grasp how openssh parses the file, you can take your host/key/config-group organization to new levels of OCD.
Happy times!
Same private key for all your servers?
@jcaleb you could use ssh-agent and load multiple keys for the session.
This is a bit of a necro, but is it possible to specify:
"Host xyz" to be "Host myusername@mywebsite"? SSH seems to crap out on me if I do that.
I better like organising my logins that way.
Try
Host myusername@ mywebsite.com
-- the space might to make ssh treat these as separate hostnames. Of course you would never be attempting to connect tomyusername@
.The problem is that
@
is the delimiter for username and hostname.You can as well use the same key pair for unlimited servers. Normally they are at ~/.ssh/, id_rsa for private key and id_rsa.pub for the public key. Run this command from your local computer and you are good to go:
cat ~/.ssh/id_rsa.pub | ssh -p22 root@server_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
And here is a more comprehensive article about it:
http://srcode.org/2014/05/07/login-ssh-without-password/
Actually, if the goal is to potentially have different private keys for different accounts on the same host, using
Match
instead ofHost
is probably the thing to do.Something like (untested)
Match user myusername host mywebsite
or possiblyoriginalhost
instead ofhost
.The answer is simple you can have as many as you want really. If you do you not want to you the same key for every server all you have to do is issue the command ssh -i key_name root@serverip and you will have your answer.
Of course you can name your keys anything you want my suggestion would be something to do with the server name so you do not get them confused. You may also wish to put them in their own folder as well to avoid clutter.