| Net::SSH::AuthorizedKeysFile(3pm) | User Contributed Perl Documentation | Net::SSH::AuthorizedKeysFile(3pm) |
Net::SSH::AuthorizedKeysFile - Read and modify ssh's authorized_keys files
use Net::SSH::AuthorizedKeysFile;
# Reads $HOME/.ssh/authorized_keys by default
my $akf = Net::SSH::AuthorizedKeysFile->new();
$akf->read("authorized_keys");
# Iterate over entries
for my $key ($akf->keys()) {
print $key->as_string(), "\n";
}
# Modify entries:
for my $key ($akf->keys()) {
$key->option("from", 'quack@quack.com');
$key->keylen(1025);
}
# Save changes back to $HOME/.ssh/authorized_keys
$akf->save() or die "Cannot save";
Net::SSH::AuthorizedKeysFile reads and modifies "authorized_keys" files. "authorized_keys" files contain public keys and meta information to be used by "ssh" on the remote host to let users in without having to type their password.
Net::SSH::AuthorizedKeysFile->new( file => "/path/other_authkeys_file" );
Normally, the "read" method described below will just silently ignore faulty lines and only gobble up keys that either one of the two parsers accepts. If you want it to be stricter, set
Net::SSH::AuthorizedKeysFile->new( file => "authkeys_file",
abort_on_error => 1 );
and read will immediately abort after the first faulty line. Also, the key parsers are fairly lenient in default mode. Adding
strict => 1
adds sanity checks before a key is accepted.
$keysfile->content( "some\nrandom\nlines\n" );
and have "parse()" operate on a string instead of an actual file this way.
Copyright 2005-2009 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
2005, Mike Schilli <m@perlmeister.com>
| 2022-10-13 | perl v5.36.0 |