Class: Servitor::SshKey
- Inherits:
-
Object
- Object
- Servitor::SshKey
- Defined in:
- lib/provisioners/ssh_key.rb
Instance Method Summary collapse
- #deploy ⇒ Object
-
#initialize(ssh_dir) ⇒ SshKey
constructor
A new instance of SshKey.
Constructor Details
#initialize(ssh_dir) ⇒ SshKey
Returns a new instance of SshKey.
3 4 5 |
# File 'lib/provisioners/ssh_key.rb', line 3 def initialize(ssh_dir) @ssh_dir = ssh_dir end |
Instance Method Details
#deploy ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/provisioners/ssh_key.rb', line 7 def deploy FileUtils.mkdir_p(@ssh_dir) FileUtils.chown(ENV['USER'], nil, @ssh_dir) home_ssh_dir = File.join(ENV['HOME'], '.ssh') private_key_file, public_key_file = %w(id_rsa id_rsa.pub).map do |key_file| File.join(home_ssh_dir, key_file).tap do |abs_key_file| FileUtils.cp(abs_key_file, File.join(@ssh_dir, File.basename(abs_key_file))) end end FileUtils.chmod(0600, private_key_file) File.open(File.join(@ssh_dir, 'authorized_keys'), 'w') do |f| f.write(File.read(public_key_file)) end end |