{"id":930,"date":"2007-04-20T01:39:52","date_gmt":"2007-04-20T08:39:52","guid":{"rendered":"http:\/\/coalface.mcslp.com\/?p=46"},"modified":"2007-04-20T01:39:52","modified_gmt":"2007-04-20T08:39:52","slug":"setting-a-remote-key-through-ssh","status":"publish","type":"post","link":"https:\/\/planet.mcb.guru\/?p=930","title":{"rendered":"Setting a remote key through ssh"},"content":{"rendered":"<p>One of the steps I find myself doing a lot is distributing round an ssh key so that I can login and use different machines automatically. To help in that process I created a small function in my bash profile script (acutally for me it&#8217;s in <code>.bash_aliases<\/code>):<\/p>\n<blockquote><p><code>function setremotekey<br \/>\n{<br \/>\n    OLDDIR=`pwd`<br \/>\n    if [ -z \"$1\" ]<br \/>\n    then<br \/>\n        echo Need user@host info<br \/>\n    fi<br \/>\n    cd $HOME<br \/>\n    if [ -e \".\/.ssh\/id_rsa.pub\" ]<br \/>\n    then<br \/>\n        cat .\/.ssh\/id_rsa.pub |ssh $1 'mkdir -p -m 0700 .ssh &#038;&#038; cat >> .ssh\/authorized_keys'<br \/>\n    else<br \/>\n        ssh-keygen -t rsa<br \/>\n        cat .\/.ssh\/id_rsa.pub |ssh $1 'mkdir -p -m 0700 .ssh &#038;&#038; cat >> .ssh\/authorized_keys'<br \/>\n    fi<br \/>\n    cd $OLDDIR<br \/>\n}<\/code><\/p><\/blockquote>\n<p>To use, whenever I want to copy my public key to a remote machine I just have to specify the login and machine: <\/p>\n<blockquote><p><code>$ setremotekey mc@narcissus<\/code><\/p><\/blockquote>\n<p>Then type in my password once, and the the function does the rest. <\/p>\n<p>How? Well it checks to make sure I&#8217;ve entered a user\/host (or actually just a string of some kind). Then, if I haven&#8217;t created a public key before (which I might not have on a new machine), I run the ssh-keygen to create it. Once the key is in place, I output the key text and then use ssh to pipe append that to the remote <code>authorized_keys<\/code> file, creating the directory along the way if it doesn&#8217;t exist. <\/p>\n<p>Short and sweet, but saves me a lot of time.\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the steps I find myself doing a lot is distributing round an ssh key so that I can login and use different machines automatically. To help in that process I created a small function in my bash profile script (acutally for me it&#8217;s in .bash_aliases):<br \/>\nfunction setremotekey<br \/>\n{<br \/>\n    OLDDIR=`pwd`<br \/>\n    [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[36],"_links":{"self":[{"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=\/wp\/v2\/posts\/930"}],"collection":[{"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=930"}],"version-history":[{"count":0,"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=\/wp\/v2\/posts\/930\/revisions"}],"wp:attachment":[{"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}