1######################################################################
2    Net::SSH::AuthorizedKeysFile 0.18
3######################################################################
4
5NAME
6    Net::SSH::AuthorizedKeysFile - Read and modify ssh's authorized_keys
7    files
8
9SYNOPSIS
10        use Net::SSH::AuthorizedKeysFile;
11
12            # Reads $HOME/.ssh/authorized_keys by default
13        my $akf = Net::SSH::AuthorizedKeysFile->new();
14
15        $akf->read("authorized_keys");
16
17            # Iterate over entries
18        for my $key ($akf->keys()) {
19            print $key->as_string(), "\n";
20        }
21
22            # Modify entries:
23        for my $key ($akf->keys()) {
24            $key->option("from", 'quack@quack.com');
25            $key->keylen(1025);
26        }
27            # Save changes back to $HOME/.ssh/authorized_keys
28        $akf->save() or die "Cannot save";
29
30DESCRIPTION
31    Net::SSH::AuthorizedKeysFile reads and modifies "authorized_keys" files.
32    "authorized_keys" files contain public keys and meta information to be
33    used by "ssh" on the remote host to let users in without having to type
34    their password.
35
36METHODS
37    "new"
38        Creates a new Net::SSH::AuthorizedKeysFile object and reads in the
39        authorized_keys file. The filename defaults to
40        "$HOME/.ssh/authorized_keys" unless overridden with
41
42            Net::SSH::AuthorizedKeysFile->new( file => "/path/other_authkeys_file" );
43
44        Normally, the "read" method described below will just silently
45        ignore faulty lines and only gobble up keys that either one of the
46        two parsers accepts. If you want it to be stricter, set
47
48            Net::SSH::AuthorizedKeysFile->new( file   => "authkeys_file",
49                                               abort_on_error => 1 );
50
51        and read will immediately abort after the first faulty line. Also,
52        the key parsers are fairly lenient in default mode. Adding
53
54            strict => 1
55
56        adds sanity checks before a key is accepted.
57
58    "read"
59        Reads in the file defined by new(). By default, strict mode is off
60        and read() will silently ignore faulty lines. If it's on (see new()
61        above), read() will immediately abort after the first faulty line. A
62        textual description of the last error will be available via error().
63
64    "content"
65        Contains the original file content, read by "read()" earlier. Can be
66        used to set arbitrary content:
67
68            $keysfile->content( "some\nrandom\nlines\n" );
69
70        and have "parse()" operate on a string instead of an actual file
71        this way.
72
73    "keys"
74        Returns a list of Net::SSH::AuthorizedKey objects. Methods are
75        described in Net::SSH::AuthorizedKey.
76
77    "as_string"
78        String representation of all keys, ultimately the content that gets
79        written out when calling the "save()" method. Note that comments
80        from the original file are lost.
81
82    "save"
83        Write changes back to the authorized_keys file using the as_string()
84        method described above. Note that comments from the original file
85        are lost. Optionally takes a file name parameter, so calling
86        "$akf->save("foo.txt")" will save the data in the file "foo.txt"
87        instead of the file the data was read from originally. Returns 1 if
88        successful, and undef on error. In case of an error, error()
89        contains a textual error description.
90
91    "sanity_check"
92        Run a sanity check on the currently selected authorized_keys file.
93        If it contains insanely long lines, then parsing with read() (and
94        potential crashes because of out-of-memory errors) should be
95        avoided.
96
97    "ssh_dir( [$user] )"
98        Locate the .ssh dir of a given user. If no user name is given,
99        ssh_dir will look up the .ssh dir of the effective user. Typically
100        returns something like "/home/gonzo/.ssh".
101
102    "path_locate( [$user] )"
103        Locate the authorized_keys file of a given user. Typically returns
104        something like "/home/gonzo/.ssh/authorized_keys". See "ssh_dir()"
105        for how the containing directory is located with and without a given
106        user name.
107
108    "error"
109        Description of last error that occurred.
110
111LEGALESE
112    Copyright 2005-2009 by Mike Schilli, all rights reserved. This program
113    is free software, you can redistribute it and/or modify it under the
114    same terms as Perl itself.
115
116AUTHOR
117    2005, Mike Schilli <m@perlmeister.com>
118
119