LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-21-2013, 08:24 PM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Rep: Reputation: 55
Is there an easy way to change SSH keys on 20 servers?


Is there an easy way to change SSH keys on 20 servers?

Since, when I change the key on the main box I won't be able to log in.
 
Old 02-21-2013, 10:21 PM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
For the last step you would need clusterssh (cssh command).

Create a text file called SERVERS where there is one server per line (e.g. user@someserver.com). Assuming you already have public key access to all of these servers and can login without being prompted for a password you could do something like the following.

Code:
cat SERVERS | while read server;do scp .ssh/new_key.pub ${server}: ;done

cssh $(cat SERVERS | tr '\n' ' ')
When you're using cssh on all of the servers at once run the following command sequence.
Code:
cat new_key.pub >> .ssh/authorized_keys
You should now be able to log into all of the servers using the new key.
Code:
ssh -i .ssh/new_key user@someserver.com
Then you can use cssh to delete the old public key out of ~/.ssh/authorized_keys on all of the servers using a text editor like vim/emacs/nano. It should get the job done quick and dirty.
 
Old 02-21-2013, 10:29 PM   #3
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Original Poster
Rep: Reputation: 55
Quote:
Originally Posted by sag47 View Post
For the last step you would need clusterssh (cssh command).

Create a text file called SERVERS where there is one server per line (e.g. user@someserver.com). Assuming you already have public key access to all of these servers and can login without being prompted for a password you could do something like the following.

Code:
cat SERVERS | while read server;do scp .ssh/new_key.pub ${server}: ;done

cssh $(cat SERVERS | tr '\n' ' ')
When you're using cssh on all of the servers at once run the following command sequence.
Code:
cat new_key.pub >> .ssh/authorized_keys
You should now be able to log into all of the servers using the new key.
Code:
ssh -i .ssh/new_key user@someserver.com
Then you can use cssh to delete the old public key out of ~/.ssh/authorized_keys on all of the servers using a text editor like vim/emacs/nano. It should get the job done quick and dirty.
Just to confirm, for this to work, I would have to rename the old key on the local box, generate a new key rename that, put the old key back, run the commands, and then rename the new key?
 
Old 02-21-2013, 11:48 PM   #4
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Yes, generate a new key with a new name so as to not overwrite the old key. You said yourself that you require access using the key so that would be the only way to do it.
 
  


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
rsync servers - ssh keys hua Linux - Security 1 02-28-2011 09:28 PM
ssh keys after the IP change avtandil_k Linux - Newbie 2 04-08-2010 01:23 PM
URGENT - Fix SSH Keys on server1 & server2(AIX Servers) to trust trust3(HP Server) chakri.unix Other *NIX 2 12-02-2008 11:20 AM
Configuring SSH to accept only keys (already have keys) fr0st Linux - Security 3 11-04-2003 03:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:59 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