Module: Webbynode::SshKeys
- Defined in:
- lib/webbynode/ssh_keys.rb
Instance Method Summary collapse
-
#add_key_to_remote(key) ⇒ Object
adds a given key string to a remote server, creating the key folder structure if needed.
- #add_key_to_remote_user(key, folder) ⇒ Object
-
#create_local_key(passphrase = "") ⇒ Object
creates the local key with an optional passphrase.
- #local_key(create_when_missing = true) ⇒ Object
-
#local_key_file ⇒ Object
name of the local publish ssh key file.
-
#remote_authorized_keys ⇒ Object
lists all authorized keys on the remote server.
-
#remote_has_key?(key) ⇒ Boolean
checks if a remote server has a given key.
Instance Method Details
#add_key_to_remote(key) ⇒ Object
adds a given key string to a remote server, creating the key folder structure if needed
5 6 7 |
# File 'lib/webbynode/ssh_keys.rb', line 5 def add_key_to_remote(key) run_remote_command "mkdir ~/.ssh 2>/dev/null; chmod 700 ~/.ssh; echo \"#{key}\" >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys" end |
#add_key_to_remote_user(key, folder) ⇒ Object
9 10 11 |
# File 'lib/webbynode/ssh_keys.rb', line 9 def add_key_to_remote_user(key, folder) run_remote_command "mkdir #{folder}/.ssh 2>/dev/null; chmod 700 #{folder}/.ssh; echo \"#{key}\" >> #{folder}/.ssh/authorized_keys; chmod 644 #{folder}/.ssh/authorized_keys" end |
#create_local_key(passphrase = "") ⇒ Object
creates the local key with an optional passphrase
31 32 33 |
# File 'lib/webbynode/ssh_keys.rb', line 31 def create_local_key(passphrase="") run "ssh-keygen -t rsa -N \"#{passphrase}\" -f #{local_key_file}" end |
#local_key(create_when_missing = true) ⇒ Object
35 36 37 38 |
# File 'lib/webbynode/ssh_keys.rb', line 35 def local_key(create_when_missing=true) create_local_key(["passphrase"]) if create_when_missing and !File.exists?(local_key_file) @local_key ||= File.read(local_key_file) end |
#local_key_file ⇒ Object
name of the local publish ssh key file
26 27 28 |
# File 'lib/webbynode/ssh_keys.rb', line 26 def local_key_file "#{ENV['HOME']}/.ssh/id_rsa.pub" end |
#remote_authorized_keys ⇒ Object
lists all authorized keys on the remote server
14 15 16 |
# File 'lib/webbynode/ssh_keys.rb', line 14 def run_remote_command "cat \$HOME/.ssh/authorized_keys" end |
#remote_has_key?(key) ⇒ Boolean
checks if a remote server has a given key
19 20 21 22 23 |
# File 'lib/webbynode/ssh_keys.rb', line 19 def remote_has_key?(key) if keys = keys.index(key) end end |