Module: GitPusshuTen::Helpers::Environment::SSHKeys
- Included in:
- Environment
- Defined in:
- lib/gitpusshuten/helpers/environment/ssh_key.rb
Instance Method Summary collapse
-
#authorized_root_ssh_keys ⇒ Object
Returns a list of authorized keys for the root user.
-
#authorized_ssh_keys ⇒ Object
Connects to the server to read out the ~/.ssh/authorized_keys.
-
#has_ssh_key? ⇒ Boolean
Returns true or false, based on whether the (local) ssh key exists.
-
#install_root_ssh_key! ⇒ Object
Installs the user’s SSH key in root’s authorized keys file.
-
#install_ssh_key! ⇒ Object
Installs the ssh key on the remote server.
-
#root_ssh_key_installed? ⇒ Boolean
ROOT.
-
#ssh_key ⇒ Object
Reads out the ssh key file contents.
-
#ssh_key_installed? ⇒ Boolean
USERS.
-
#ssh_key_path ⇒ Object
Returns the default (local) SSH key path.
Instance Method Details
#authorized_root_ssh_keys ⇒ Object
Returns a list of authorized keys for the root user
64 65 66 |
# File 'lib/gitpusshuten/helpers/environment/ssh_key.rb', line 64 def execute_as_root("cat $HOME/.ssh/authorized_keys") end |
#authorized_ssh_keys ⇒ Object
Connects to the server to read out the ~/.ssh/authorized_keys
31 32 33 |
# File 'lib/gitpusshuten/helpers/environment/ssh_key.rb', line 31 def execute_as_root("cat '#{File.join(home_dir, '.ssh', 'authorized_keys')}'") end |
#has_ssh_key? ⇒ Boolean
Returns true or false, based on whether the (local) ssh key exists
19 20 21 |
# File 'lib/gitpusshuten/helpers/environment/ssh_key.rb', line 19 def has_ssh_key? File.exist?(ssh_key_path) end |
#install_root_ssh_key! ⇒ Object
Installs the user’s SSH key in root’s authorized keys file
70 71 72 73 74 |
# File 'lib/gitpusshuten/helpers/environment/ssh_key.rb', line 70 def install_root_ssh_key! command = "mkdir -p $HOME/.ssh; echo '#{ssh_key}' >> $HOME/.ssh/authorized_keys;" command += "chmod 700 $HOME/.ssh; chmod 600 $HOME/.ssh/authorized_keys" execute_as_root(command) end |
#install_ssh_key! ⇒ Object
Installs the ssh key on the remote server
43 44 45 46 47 48 49 |
# File 'lib/gitpusshuten/helpers/environment/ssh_key.rb', line 43 def install_ssh_key! command = "mkdir -p '#{File.join(home_dir, '.ssh')}';" command += "echo '#{ssh_key}' >> '#{File.join(home_dir, '.ssh', 'authorized_keys')}';" command += "chown -R #{c.user}:#{c.user} '#{File.join(home_dir, '.ssh')}';" command += "chmod 700 '#{File.join(home_dir, '.ssh')}'; chmod 600 '#{File.join(home_dir, '.ssh', 'authorized_keys')}'" execute_as_root(command) end |
#root_ssh_key_installed? ⇒ Boolean
ROOT
Checks to see if the user’s key is already installed in the authorized keys of the root user on the remote server
56 57 58 59 60 |
# File 'lib/gitpusshuten/helpers/environment/ssh_key.rb', line 56 def root_ssh_key_installed? return false unless has_ssh_key? return true if .include?(ssh_key) false end |
#ssh_key ⇒ Object
Reads out the ssh key file contents
25 26 27 |
# File 'lib/gitpusshuten/helpers/environment/ssh_key.rb', line 25 def ssh_key File.read(ssh_key_path) end |
#ssh_key_installed? ⇒ Boolean
USERS
Returns true or false, based on whether the (local) ssh key has been installed on the remote server or not
11 12 13 14 15 |
# File 'lib/gitpusshuten/helpers/environment/ssh_key.rb', line 11 def ssh_key_installed? return false unless has_ssh_key? return true if .include?(ssh_key) false end |
#ssh_key_path ⇒ Object
Returns the default (local) SSH key path
37 38 39 |
# File 'lib/gitpusshuten/helpers/environment/ssh_key.rb', line 37 def ssh_key_path File.join(ENV['HOME'], '.ssh', c.ssh_key || 'id_rsa.pub') end |