Module: VagrantPlugins::RekeySSH::Helpers

Included in:
ActionSSHInfo, ActionSecureBox
Defined in:
lib/vagrant-rekey-ssh/helpers.rb

Instance Method Summary collapse

Instance Method Details

#generate_ssh_keyObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant-rekey-ssh/helpers.rb', line 8

def generate_ssh_key
  unless ::File.exists?(ssh_key_path)

    @machine.ui.info(I18n.t("vagrant_rekey_ssh.info.generating_key"))
              
    key = SSHKey.generate(:comment => "vagrant less insecure private key")
    begin
      File.write(ssh_key_path, key.private_key)
      # Fix ssh key permissions on Unix systems
      File.chmod(600, ssh_key_path) if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) == nil
      File.write(ssh_pubkey_path, key.ssh_public_key)
    rescue => exc
      raise Errors::ErrorCreatingSshKey, error_message: exc.message
    end
    
    @machine.ui.info(I18n.t("vagrant_rekey_ssh.info.key_generated", :path => ssh_key_path))
    
  end
end

#rekey_sentinel_fileObject



28
29
30
# File 'lib/vagrant-rekey-ssh/helpers.rb', line 28

def rekey_sentinel_file
  ::File.join(@machine.data_dir, "rekey_sentinel")
end

#ssh_key_pathObject



36
37
38
# File 'lib/vagrant-rekey-ssh/helpers.rb', line 36

def ssh_key_path
  ::File.join(@env[:home_path], "less_insecure_private_key")
end

#ssh_pubkey_pathObject



40
41
42
# File 'lib/vagrant-rekey-ssh/helpers.rb', line 40

def ssh_pubkey_path
   ::File.join(@env[:home_path], "less_insecure_private_key.pub")
end

#ssh_public_keyObject



32
33
34
# File 'lib/vagrant-rekey-ssh/helpers.rb', line 32

def ssh_public_key
  IO.read(ssh_pubkey_path).scan( /^(\S+\s+\S+).*$/ ).last.first
end