Add an ssh key to another user on a different system without logging in

Scott liked my terminal style from yesterday, so I’ll reprise it.


heian:<<<umi-misc/pubkeys$ ssh cse125@neathat.com -p 14522 sudo ls \>/dev/null
[sudo] password for cse125: (echoed, which is unfortunate)
heian:<<<umi-misc/pubkeys$ cat djc_hmac_rsa.pub | ssh cse125@neathat.com -p 14522 sudo su -c \'cat \>\> ~djc/.ssh/authorized_keys\'
heian:<<<umi-misc/pubkeys$

Now DJ can use his key on that server.

The sudo ls is to enter the password and get the sudo authorization ticket. We can’t enter the password with the cat, because ssh sees its stdin isn’t a terminal and refuses to allocate a tty. A stupid workaround would be (echo "mypassword"; cat ... ); | ssh ..., but I like the two-phase solution more, for some reason.

2 Responses to “Add an ssh key to another user on a different system without logging in”

  1. Brad says:

    Wow, Neat Hat looks like lots of fun. You guys have an unstoppable team.

  2. BOUGHTER says:

    Just commenting on the new design; looking real good man.

Leave a Reply


Or, enter your OpenID URL to log in: (cookies required)

Just another WordPress weblog