Net-SSH-Perl
view release on metacpan or search on metacpan
eg/pssh-keygen view on Meta::CPAN
unless ($new) {
$new = prompt("Enter new comment:");
}
$key->write_private($keyfile, $pass, $new);
write_public($keyfile, $key, $new);
print "The comment in your key file has been changed.\n";
}
elsif ($opts{l}) {
print $key->size, " ", $key->fingerprint, "\n";
}
elsif ($opts{B}) {
print $key->size, " ", $key->fingerprint('bubblebabble'), "\n";
}
elsif ($opts{y}) {
print $key->dump_public, "\n";
}
elsif ($opts{x}) {
my $comment = $key->size .
"-bit $key_type, converted from Net::SSH::Perl";
(my $pub = encode_base64($key->as_blob, '')) =~ s!(.{1,70})!$1\n!g;
print qq(---- BEGIN SSH2 PUBLIC KEY ----\n),
qq(Comment: "$comment"\n),
$pub,
qq(---- END SSH2 PUBLIC KEY ----\n);
}
}
elsif ($opts{X}) {
my $keyfile;
unless ($keyfile = $opts{f}) {
$keyfile = prompt("Enter file in which the key is:", $def_keyfile);
}
my $key = Net::SSH::Perl::Key->new('DSA');
require Crypt::DSA::Key;
$key->{dsa} = Crypt::DSA::Key->new(
Filename => $keyfile,
Type => 'SSH2'
);
die "Loading key failed" unless $key->{dsa};
print $key->write_private;
}
else {
debug("Generating public/private $type key pair.");
my $key = Net::SSH::Perl::Key->keygen($key_type, $opts{b});
my $keyfile;
unless ($keyfile = $opts{f}) {
$keyfile = prompt("Enter file in which to save the key:", $def_keyfile);
}
my $pass = $opts{N};
unless ($pass) {
$pass = _read_passphrase("Enter new passphrase (empty for no passphrase): ");
my $again = _read_passphrase("Enter same passphrase again: ");
die "Pass phrases do not match. Try again.\n"
unless $pass eq $again;
}
use Sys::Hostname;
my $comment = getpwuid($<) . '@' . hostname;
$key->write_private($keyfile, $pass);
chmod 0600, $keyfile or die "Can't chmod $keyfile to 0600: $!";
debug("Your identification has been saved in $keyfile.");
my $pub = write_public($keyfile, $key, $comment);
debug("Your public key has been saved in $pub.");
debug("The key fingerprint is:");
debug($key->fingerprint);
}
sub write_public {
my($priv_keyfile, $key, $comment) = @_;
$comment ||= '';
my $pub = "$priv_keyfile.pub";
local *FH;
open FH, ">$pub" or die "Can't open public keyfile $pub: $!";
print FH $key->dump_public;
print FH " ", $comment, "\n";
close FH or warn "Can't close public keyfile $pub: $!";
$pub;
}
sub debug {
print STDERR "@_\n" if $VERBOSE;
}
sub prompt {
my($msg, $def) = @_;
print "$msg " . ($def ? "[$def] " : "");
chomp(my $ans = <STDIN>);
$ans ? $ans : $def;
}
__END__
=head1 NAME
pssh-keygen - Authentication key generation/management
=head1 SYNOPSIS
pssh-keygen [B<-q>] [B<-b> I<bits>] [B<-t> I<type>] [B<-N>
I<new_passphrase>] [B<-f> I<output_keyfile>]
pssh-keygen B<-p> [B<-P> I<old_passphrase>] [B<-N>
I<new_passphrase>] [B<-f> I<keyfile>]
pssh-keygen B<-x> [B<-f> I<input_keyfile>]
pssh-keygen B<-X> [B<-f> I<input_keyfile>]
pssh-keygen B<-y> [B<-f> I<input_keyfile>]
pssh-keygen B<-c> [B<-P> I<passphrase>] [B<-C> I<comment>]
[B<-f> I<keyfile>]
pssh-keygen B<-l> [B<-f> I<input_keyfile>]
( run in 1.423 second using v1.01-cache-2.11-cpan-39bf76dae61 )