Module: Sshakery

Defined in:
lib/sshakery.rb,
lib/sshakery/version.rb,
lib/sshakery/auth_keys.rb

Overview

About

Sshakery is a module for manipulating OpenSSH authorized_keys files

  • Some of its features include:

    atomic writes

    thread and process safe file locking (through flock)

    method naming conventions similar to Rails

    unit tests

Help

For more information regarding wich options are supported please run:

man sshd

Additionally here are some good articles:

www.eng.cam.ac.uk/help/jpmg/ssh/authorized_keys_howto.html

www.hackinglinuxexposed.com/articles/20030109.html

Usage

require 'sshakery'

# instantiate key file object
keys = Sshakery.load '/path/to/.ssh/authorized_keys'

# return array of all keys
all_keys = keys.all

# grab a single key
key = all_keys[0]

# add forced command to key
key.command = 'ls'
key.save

# return only keys where the note == 'foo'
somekeys = keys.find_all_by :note=>'foo'

# return only keys where the note == 'foo' and the key_type == 'ssh-rsa'
somekeys = keys.find_all_by :note=>'foo', :key_type=>'ssh-rsa'

Defined Under Namespace

Modules: Errors, FsUtils Classes: AuthKeys

Constant Summary collapse

VERSION =

Sshakery version

"0.0.6"

Class Method Summary collapse

Class Method Details

.load(path, lock_path = nil) ⇒ Object

Load an authorized_keys file and return an Authkeys class for manipulation

Args :

path -> Path to authorized_keys file

lock_path -> Path to shared lock file

Returns :

AuthKeys -> A new AuthKeys class configured to edit the path



62
63
64
65
66
67
# File 'lib/sshakery.rb', line 62

def self.load path, lock_path=nil
    new = Class.new(AuthKeys)
    new.path = path
    new.temp_path = lock_path || 'sshakery.temp'
    return new
end