#!/usr/bin/perl -w # $Id: import_putty_key,v 1.3 2004/06/02 08:59:32 hom Exp $ my $line=''; my $state = 0; my $file=$ARGV[0]; my $dirname=$ENV{'HOME'}; my $comment=''; my $keyfile='authorized_keys'; $dirname .= '/.ssh'; if (scalar @ARGV == 0) { print < This script imports a putty keygen key as used by putty and pageant into a ssh2 authorized key format. This file only understands SSH2 RSA keys and of those only one per file. Example: import_putty_key fontysvenlo.pub EOF exit(0); } open(FILE,"<$file") or die "cannot open file $file\n"; while() { chomp; # print "$_\n"; if (m/\-{4} BEGIN SSH2 PUBLIC KEY \-{4}/) { $state =1; } elsif ( m/^Comment: \"(\S+)\"/) { $comment = $1; } elsif (!m/\-{4}\sEND\sSSH2\sPUBLIC\sKEY\s\-{4}/) { $line .= $_; } } close(FILE); print STDERR "installing in $dirname\n"; mkdir $dirname,0700 unless -d $dirname; open(SSHAUTH,">>$dirname/$keyfile") or die "cannot open $keyfile file\n"; print STDERR "installing key with comment: $comment\n"; print SSHAUTH "ssh-rsa $line $comment\n"; close(SSHAUTH); print STDERR "done\n";