Class: VagrantPlugins::Blockwart::SshConf

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-blockwart/sshconf.rb

Instance Method Summary collapse

Constructor Details

#initializeSshConf

Returns a new instance of SshConf.



7
8
9
10
# File 'lib/vagrant-blockwart/sshconf.rb', line 7

def initialize()
	touch()
	@ssh_config = ConfigFile.new
end

Instance Method Details

#remove_host(host) ⇒ Object



50
51
52
# File 'lib/vagrant-blockwart/sshconf.rb', line 50

def remove_host(host)
	@ssh_config.rm!(host)
end

#remove_hosts(hosts) ⇒ Object



54
55
56
57
58
59
# File 'lib/vagrant-blockwart/sshconf.rb', line 54

def remove_hosts(hosts)
	hosts.each do |host|
		@ssh_config.rm(host)
	end
	@ssh_config.save()
end

#touchObject



12
13
14
15
16
17
# File 'lib/vagrant-blockwart/sshconf.rb', line 12

def touch()
	unless File.directory?(ENV['HOME'] + "/.ssh")
				FileUtils.mkdir_p(ENV['HOME'] + "/.ssh")
	end
	FileUtils.touch(ENV['HOME'] + "/.ssh/config")
end

#update(host, ssh_info) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vagrant-blockwart/sshconf.rb', line 19

def update(host, ssh_info)
	@ssh_config.set(host, 'HostName', ssh_info[:host])
	@ssh_config.set(host, 'Port', ssh_info[:port])
	@ssh_config.set(host, 'User', ssh_info[:username])
	
	ssh_keys = ssh_info[:private_key_path]
	ssh_keys.each do |ssh_key|
		@ssh_config.set(host, 'IdentityFile', ssh_key)
	end

	if ssh_info[:forward_agent]
		@ssh_config.set(host, 'ForwardAgent', 'yes')
	end

	if ssh_info[:forward_x11]
		@ssh_config.set(host, 'ForwardX11', 'yes')
	end

	if ssh_info[:proxy_command]
		@ssh_config.set(host, 'ProxyCommand', ssh_info[:proxy_command])
	end

	@ssh_config.set(host, 'UserKnownHostsFile', '/dev/null')
	@ssh_config.set(host, 'StrictHostKeyChecking', 'no')
	@ssh_config.set(host, 'PasswordAuthentication', 'no')
	@ssh_config.set(host, 'IdentitiesOnly', 'yes')
	@ssh_config.set(host, 'LogLevel', 'FATAL')
	
	@ssh_config.save()
end