Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Bash function to copy SSH DSA public key to a new server (See related posts)

Or, "How to login over SSH without a password".

First of all, you'll need to have generated an SSH public DSA key using the following commands:

cd ~ && ssh-keygen -t dsa


Then, you can add the following bash function to your .bashrc (or similar) and just type 'scpdsa user@hostname' to add your public key to your 'authorized_keys' file on the server.

function scpdsa {
  if [[ -z "$1" ]]; then
    echo "!! You need to enter a hostname in order to send your public key !!" 
  else
    echo "* Copying SSH public key to server..." 
    ssh ${1} "mkdir -p ~/.ssh && cat - >> ~/.ssh/authorized_keys" < ~/.ssh/id_dsa.pub
    echo "* All done!"
  fi
}


-- updated to use simpler and quicker method.

Comments on this post

sam posts on Jun 15, 2005 at 19:53
Or you can just do this from a shell:

$ ssh username@host 'cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_dsa.pub

You need to create an account or log in to post comments to this site.


Related Posts