Net::S...ysFile(3pm)
πΈ NAME πΈ
Net::SSH::AuthorizedKeysFile</p> β the module that reads and modifies ssh's authorized_keys files. That's the whole vibe. This doc page is <hotpink>Net::S...ysFile(3pm)</hotpink> from the User Contributed Perl Documentation corner of the internet, and bestie, it's about to be your new fave thing ever π
π¦ SYNOPSIS π¦
okay so here's the whole idea in one go, look:
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";
β¨ no cap. read, vibe check, tweak, save. that's it β¨
π DESCRIPTION π
Net::SSH::AuthorizedKeysFile reads and modifies "authorized_keys" files. And what even are those, you ask? π₯Ί "authorized_keys" files hold public keys plus meta info, and ssh on the remote host uses them to let users in without having to type their password. it's giving keycard energy, but for ssh π
π METHODS π
new
Creates a brand new Net::SSH::AuthorizedKeysFile object and reads in the authorized_keys file, all in one go. main character behavior fr fr.
The filename defaults to $HOME/.ssh/authorized_keys unless you override it like this:
Net::SSH::AuthorizedKeysFile->new( file => "/path/other_authkeys_file" );
Now here's the tea π΅ β normally the "read" method (right below, bestie) just silently ignores faulty lines and only gobbles up keys that either one of the two parsers accepts. adorable. but if you want it to be stricter, set this:
Net::SSH::AuthorizedKeysFile->new( file => "authkeys_file",
abort_on_error => 1 );
and then read will immediately abort after the first faulty line. π
Also (there's more!!), the key parsers are fairly lenient in default mode. Adding
strict => 1
adds sanity checks before a key is accepted. bougie behavior β¨
read
Reads in the file defined by new(). By default, strict mode is off and read() will silently ignore faulty lines. If it's on (peep new() above for that), read() will immediately abort after the first faulty line. A textual description of the last error will be available via error(). so if something goes sideways, that's where the receipts live π§Ύ
content
Contains the original file content, read by "read()" earlier. You can also use it to set arbitrary content:
$keysfile->content( "some\nrandom\nlines\n" );
and have "parse()" operate on a string instead of an actual file this way. slay, honestly π
keys
Returns a list of Net::SSH::AuthorizedKey objects. All their methods are described over in Net::SSH::AuthorizedKey. go peek, iykyk π
as_string
String representation of all keys β ultimately the content that gets written out when you call the "save()" method. Note that comments from the original file are lost. π she's honest about it.
save
Write changes back to the authorized_keys file using the as_string() method described above. And yes, note that comments from the original file are lost. again. tragic but true.
It optionally takes a file name parameter, so calling $akf->save("foo.txt") will save the data in the file foo.txt instead of the file the data was read from originally. π«Ά
Returns 1 if successful, and undef on error. In case of an error, error() contains a textual error description. periodt.
sanity_check
Run a sanity check on the currently selected authorized_keys file. If it contains insanely long lines, then parsing with read() (and potential crashes because of out-of-memory errors) should be avoided. bestie. please. do the vibe check first π
ssh_dir( [$user] )
Locate the .ssh dir of a given user. If no user name is given, ssh_dir will look up the .ssh dir of the effective user. Typically returns something like "/home/gonzo/.ssh". π
path_locate( [$user] )
Locate the authorized_keys file of a given user. Typically returns something like "/home/gonzo/.ssh/authorized_keys". See "ssh_dir()" for how the containing directory is located with and without a given user name. π«
error
Description of last error that occurred. your little error diary π
β LEGALESE β
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. iconic legal boilerplate, we respect it π
π AUTHOR π
2005, Mike Schilli <m@perlmeister.com>
and that's the whole page bestie!! π¦ this was perl v5.36.0, dated 2022-10-13, and yes the footer literally says Net::S...ysFile(3pm) π go forth and manage those keys, you absolute legend πβ¨
π¦ where this page comes from
- ubuntu noble: libnet-ssh-authorizedkeysfile-perl 0.18-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libnet-ssh-authorizedkeysfile-perl 0.18-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libnet-ssh-authorizedkeysfile-perl 0.18-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms