See http://www.mtu.net/~engstrom/ssh-agent.php#PuTTYGen, but basically this involves creating a key-pair and putting the public key on the server side in the ~/.ssh directory. This also works for getting CVS over SSH to work without having to type the password more than once per session.
Update:
.bash_profile:
SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
eval `$SSHAGENT $SSHAGENTARGS`
trap "kill $SSH_AGENT_PID" 0
fi
.bash_logout:
if [ ${SSH_AGENT_PID+1} == 1 ]; then
ssh-add -D
ssh-agent -k > /dev/null 2>&1
unset SSH_AGENT_PID
unset SSH_AUTH_SOCK
fi
For more information, see http://mah.everybody.org/docs/ssh.
Here's a script to set up SSH Agent:
#!/usr/bin/perl -w
my %config = ( sshdir => $ENV{'HOME'} . "/.ssh",
);
$config{'keyfile'} = $config{'sshdir'} . "/auto_rsa";
$config{'authkeys'} = $config{'sshdir'} . "/authorized_keys";
$config{'bash_profile'} = $ENV{'HOME'} . "/.bash_profile";
$config{'bash_logout'} = $ENV{'HOME'} . "/.bash_logout";
# prep: create ~/.ssh
if (! -d $config{'sshdir'} ) {
print "Creating SSH directory '" . $config{'sshdir'} . "'...\n";
mkdir($config{'sshdir'}) || die "Error creating dir: $!";
}
# Create SSH (RSA) keys
print "Creating keys...\n";
system("ssh-keygen -t rsa " .
" -f " . $config{'keyfile'} .
" -q -P \"\"");
# Copy public key into the authorized keys
open(PUBKEY, $config{'keyfile'}.".pub")
|| die "Error opening '".$config{'keyfile'}.".pub': $!";
open(AUTH, ">>" . $config{'authkeys'})
|| die "Error appending to '" .$config{'authkeys'}. "': $!";
$_ = <PUBKEY>;
print AUTH $_;
close(AUTH);
close(PUBKEY);
# add commands into ~/.bash_profile
open(BASHPROFILE, ">>" . $config{'bash_profile'})
|| die "Error appending to '".$config{'bash_profile'}."': $!";
print BASHPROFILE <<EOD;
# AUTO ADDED BY SSHSETUP SCRIPT
# to start the SSH-agent
if [ -z "\$SSH_AUTH_SOCK" ] ; then
eval `ssh-agent -s`
ssh-add $config{'keyfile'}
fi
# END AUTO ADDED BY SSHSETUP SCRIPT
EOD
close(BASHPROFILE);
# add command into ~/.bash_logout
open(BASHLOGOUT, ">>" . $config{'bash_logout'})
|| die "Error appending to '".$config{'bash_logout'}."': $!";
print BASHLOGOUT <<EOD;
# AUTO ADDED BY SSHSETUP SCRIPT
kill ssh-agent
ssh-agent -k
# END AUTO ADDED BY SSHSETUP SCRIPT
EOD
close(BASHLOGOUT);
This script is not safe! Running it more than once, or if you already have SSH agent set-up, might cause damage to your setup, or at the very least will add more cruft to your logon scripts
As for Windows, and the Pageant, you'll have to use the puttygen program to convert it from the OpenSSH key that the ssh-keygen generated. To that, run ssh-keygen and select "Load Private Key", and load the private key (not the file with the .pub extension.) And then press "Save Private Key", which will give you a .ppk file that Pageant will accept. See http://linux-sxs.org/networking/openssh.putty.html for more information.
Last updated on 2009-05-05 01:52:19 -0800, by Shalom CraimerBack to Tech Journal