cmv has asked for the wisdom of the Perl Monks concerning the following question:
I have 2 questions here:
1.) Is this a reasonable implementation for populating the authorized_keys file for a user on a remote system under their login?
2.) Is doing this compromising security any?
The implementation relies on using expect to handle transporting the users typed-in password to ssh in order to populate far-end authorized_keys the first time. Thereafter the users ssh requests will not need a password anymore.
This requires that the user already has a public and private key setup on their local system. It does not need to worry about wether or not the private key is password protected or not. It just ships the public key over to the target system and installs it into their authorized_keys file.
The only thing I came up with in super-search on this topic, was scp and ssh without passwd, and I couldn't understand why doing this was effecting security any.
Thanks
-Craig
PS - Also, any suggested improvements are welcome!
UPDATE: s/crap/authorized_keys in example program
use strict; use warnings; use Expect; use Term::ReadKey; my $exp = new Expect; my $usr = 'myuser'; my $host = 'myhost'; my $pubkey = `cat $ENV{HOME}/.ssh/id_rsa.pub`; if(!$pubkey) { die "No public key" }; $exp->spawn("ssh $usr\@$host 'echo \"$pubkey\" >>.ssh/authorized_keys' +") || die "Dead Spawn"; $exp->expect(15, # This handles a first-time query from ssh about adding the target # machine to your known_hosts file if it isn't already there... [ '-re', '.*\(yes/no\)\? ', sub{ $exp->send("yes\n"); $exp->exp_continue; } ], # This handles the password prompt... [ 'assword: ', sub{ $exp->send(_GetPass($host, $usr) . "\r"); $exp->exp_continue; } ], # Handling EOF... [eof => sub { print "\nERROR: Got an EOF...\n"; } ], # Handling timeouts... [timeout => sub { die "\nERROR: Got a Timeout..\n"; } ], ); # This normally would be a GUI popup... sub _GetPass { my $host = shift || die "Missing host"; my $usr = shift || die "Missing usr"; ReadMode('noecho'); print "Enter $usr" . '@' . "$host Password: "; chomp(my $pw = ReadLine(0)); ReadMode('restore'); print "\n"; return ( $pw ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Populating authorized_keys with Expect
by almut (Canon) on Nov 24, 2008 at 19:52 UTC | |
by Xilman (Hermit) on Nov 25, 2008 at 12:29 UTC | |
|
Re: Populating authorized_keys with Expect
by salva (Canon) on Nov 24, 2008 at 21:15 UTC | |
|
Re: Populating authorized_keys with Expect
by jethro (Monsignor) on Nov 24, 2008 at 20:47 UTC | |
|
Why I'm Populating authorized_keys with Expect
by cmv (Chaplain) on Nov 25, 2008 at 15:13 UTC | |
by salva (Canon) on Nov 25, 2008 at 15:58 UTC | |
by cmv (Chaplain) on Nov 25, 2008 at 17:41 UTC | |
by salva (Canon) on Nov 26, 2008 at 09:12 UTC | |
by cmv (Chaplain) on Nov 26, 2008 at 16:03 UTC | |
|