Find the answer to your Linux question:
Results 1 to 3 of 3
Hi All I'm new to linux.I need to add one ssh key & remove another key in 20 RHEL remote servers. key to delete: ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqgYqpC+019HDOc5MJ1MqTm 01iubY0nQqbbbjODRWgUlyH+uLUM+NLHpPaWKlVPNpGLmg0uK+ bOXXUprLGxAAHQKgF141lgBPCjW3VfFwTDtK3d1yEOcbMULCBB Bvui2NViUJCkExK7CRO== user1 ...
  1. #1
    Just Joined!
    Join Date
    Jul 2008
    Posts
    5

    Arrow add/remove ssh keys using shell script

    Hi All

    I'm new to linux.I need to add one ssh key & remove another key in 20 RHEL remote servers.

    key to delete:
    ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqgYqpC+019HDOc5MJ1MqTm 01iubY0nQqbbbjODRWgUlyH+uLUM+NLHpPaWKlVPNpGLmg0uK+ bOXXUprLGxAAHQKgF141lgBPCjW3VfFwTDtK3d1yEOcbMULCBB Bvui2NViUJCkExK7CRO== user1

    key to add:
    ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0TGyZUJD43KsHWZhJJuPr3 UB5ubTVT1wE+ffQYJkIiE2539u8v5SVpWHWq6QEB/nDS0CEQPZzO91iqw652Pm+eLTlLf+JJ/jb5uqMdN0ErJcrBn0ILUfjbMRHKj2pry/mV87QhL4bhJRc== user2

    My idea is to add key that has to be add/remove in text file (key.txt) and server ip's (ip.txt).Then call these files using script.

    To add key : nothing has to be compared as i'm sure this is new key.the new key shud be appended in .ssh/authorized_keys

    to remove key: we have to compare all the existing keys in remote server with the present key which we are removing...remove that key & save .ssh/authorized_keys

    Can any one provide two scripts (to add & remove) for this requirement.I hope that is good to copy already existing keys to tmp..then do the changes.. I have little knowledge in programming so providing complete script will be very much helpful

    Let me know if any other easy method is possible..Plz share your opinions

    Thanks in Advance
    SSK Raju

  2. #2
    Just Joined!
    Join Date
    Feb 2009
    Posts
    54
    You can try and write a Perl script that will do this easily for you if you have do it on 100's of servers. Hint: Net::SSH::Perl

    But just for 20 servers, I'd suggest just log in and do it manually:
    vi the $HOME/.ssh/authorized_keys(2) file and delete the line with the key you need to remove, and copy/paste the new one (be careful of extraneous newline characters).

  3. #3
    Linux Newbie
    Join Date
    Sep 2007
    Posts
    161
    hi SSK Raju,

    are you familiar with the ssh-add tool? it seems to do exactly what you are asking for (or else, I didn't get what you are trying to do, in which case, maybe you can clarify).

    I particular, ssh-add supports a "-d" flag for removing keys.

    Of course, this still leaves the problem of logging into your 20 servers and executing those ssh-add commands.

    cheers, kai

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...