Skip to content

ofca/OpenSSH

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What it is?

PHP classes for parsing OpenSSH authorized_keys file and more.

NOTE: Supported is only SSH2 protocol.

What this can do for me?

  • Return all keys from authorized_keys file
  • Insert key to authorized_keys file
  • Remove key from authorized_keys file
  • Validate line from authorized_keys file
  • Return options for key (you know, like command, no-port-forwarding, no-agent-forwarding ect.)
  • Validate plain SSH key
  • Return SSH key type, "key" or comment.

Examples

Validate SSH key

try {
    $key = new \OpenSSH\SSHKey('ssh-rsa AAAAksf...sdfa== [email protected]');
} catch (\InvalidArgumentException $e) {
    // This exception is throwed if you provide empty string (or not string), 
    // or string has some break lines inside
    echo $e->getMessage();
} catch (\OpenSSH\Exception\MalformedSSHKey $e) {
    // This exception is throwed if key is in bad format.
    echo $e->getMessage();
}

Validate line from authorized_keys file

try {
    $key = new \OpenSSH\AuthorizedKey('command="/bin/echo hello",no-X11-forwarding,no-agent-forwarding,no-port-forwarding ssh-rsa AAAAB3NzaC...cAQ==');
} catch (\OpenSSH\Exception\MalformedAuthorizedKey $e) {
    // This exception is throwed if key is in bad format.
    echo $e->getMessage();
}

Get key options

$key = new \OpenSSH\AuthorizedKey('command="/bin/echo hello",no-X11-forwarding,no-agent-forwarding,no-port-forwarding ssh-rsa AAAAB3NzaC...cAQ==');

$key->hasOption('no-X11-forwarding'); // return true
$key->hasOption('no-agent-forwarding'); // return true
$key->hasOption('tunnel'); // return false
$key->getOption('command'); // return /bin/echo hello

More examples in progress... (If you need more exampleslook at tests).

About

PHP classes for parsing OpenSSH authorized_keys file

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages