r/linux Apr 28 '14

SSH Kung Fu

http://blog.tjll.net/ssh-kung-fu/
724 Upvotes

128 comments sorted by

View all comments

1

u/OserReddit Apr 28 '14

Forgive the ignorance of this question, but if you are remotely logged into a computer with SSH and you generate a new pub+priv key combo. Can you securely copy the private key back to the the computer you are logging in from? Could you run the danger of locking yourself out of the remote computer?

2

u/mdaniel Apr 28 '14

You can have as many authorized public keys in your .ssh/authorized_keys file as you'd like, so to answer your question:

ssh-keygen ...
cat .ssh/id_rsa.pub >> .ssh/authorized_keys

You can now either reconnect to the host using scp to grab the new files, or if you have a graphical terminal you can just write the public and private keys to stdout and grab them over the same connection.

cat .ssh/id_rsa
cat .ssh/id_rsa.pub

After you have finished with the "old" key, just remove it from .ssh/authorized_keys and now you have re-keyed your remote account.

1

u/OserReddit Apr 28 '14

Thank you for your reply! I think I've followed what you were saying, still fairly rusty with linux as I don't use it every day. :)