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 script to export ssh public key to a remote server (See related posts)

This isn't a brilliant script, but it sure can be a time saver. When I add a public key by hand I end up doing a lot more commands.

#!/bin/bash

## USAGE: add_to_server.sh remote_server

## This script will add your ssh dsa public key to remote_server's authorized_keys list, 
## assuming that everything is in it's default location

set -v                                 # verbose output
username="USERNAME"              # CHANGE ME!!!!
remote_server=$1              # assigns the first commandline argument to $remote_server


## Pipe the public key to ssh, then remotely touch the file to make sure it will be there, and concat to the end of it.
## Might work without the touch?
cat ~/.ssh/id_dsa.pub | ssh ${username}@${remote_server} "touch ~/.ssh/authorized_keys && cat - >> ~/.ssh/authorized_keys"

exit 0

Comments on this post

judas_iscariote posts on Jun 02, 2006 at 06:32
this is easier .

ssh-copy-id ~/.ssh/id_dsa.pub [email protected]

;-)
judas_iscariote posts on Jun 02, 2006 at 06:35
ssh-copy-id -i ~/.ssh/id_dsa.pub [email protected]

I mean.

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


Related Posts