key-installer 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README.rdoc +25 -0
  2. data/bin/install-key +3 -0
  3. data/lib/key_installer.rb +72 -0
  4. metadata +68 -0
@@ -0,0 +1,25 @@
1
+ = SSH Key Installation
2
+
3
+ A tiny script to copy your SSH public keys from your local machine to
4
+ a remote server. It'll search your .ssh/ folder for known public keys
5
+ and if it finds one, it'll add it to the remote authorized_keys file.
6
+
7
+ == Install
8
+
9
+ gem sources -a http://gems.github.com
10
+ sudo gem install adamcooke-key-installer
11
+
12
+ == Usage
13
+
14
+ Install the default public key to a server called myserver.com for a
15
+ user called 'dave'
16
+
17
+ install-key dave@myserver.com
18
+
19
+ Install a key from /home/user/my_key.pub to a server
20
+
21
+ install-key phil@anotherserver.com --key /home/user/my_key.pub
22
+
23
+ Install default keys to a server running an un-standard SSH port
24
+
25
+ install-key sarah@mylittlebox.com -p 12345
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + "/../lib/key_installer"
3
+ KeyInstaller.run(ARGV)
@@ -0,0 +1,72 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ module KeyInstaller
4
+
5
+ ## A very simple script to push an SSH key to a remote host via. SSH.
6
+
7
+ extend self
8
+
9
+ attr_reader :options
10
+
11
+ def run(args)
12
+ install_key(args.shift, args)
13
+ end
14
+
15
+ private
16
+
17
+ def install_key(host, args)
18
+
19
+ if host.nil?
20
+ puts " ** Hostname was not provided (e.g. install-key dave@myserver.com)"
21
+ return
22
+ end
23
+
24
+ args_to_options(args)
25
+ if options.keys.include?('key')
26
+ if File.exist?(options['key'])
27
+ public_key = File.read(options['key'])
28
+ else
29
+ puts " ** Key not found in '#{options['key']}'"
30
+ end
31
+
32
+ else
33
+ ## Find a key from the .ssh folder
34
+ for possible_key in %w{id_rsa.pub id_dsa.pub}
35
+ path_to_key = File.join(ENV['HOME'], '.ssh', possible_key)
36
+ if File.exist?(path_to_key)
37
+ public_key = File.read(path_to_key)
38
+ break
39
+ end
40
+ end
41
+ end
42
+
43
+ ## Set the command to run on the remote server:
44
+ ssh_command = %Q{echo '#{public_key}' | ssh #{host} -p #{ssh_port} "mkdir -p .ssh && cat - >> .ssh/authorized_keys"}
45
+
46
+ if %x[ #{ssh_command} ] == ''
47
+ puts " ** Key installed to '#{host}' successfully."
48
+ else
49
+ puts " ** Sorry, something went wrong and the world will now end."
50
+ end
51
+
52
+ end
53
+
54
+ def ssh_port
55
+ @options['port'] || @options['p'] || 22
56
+ end
57
+
58
+ def args_to_options(args)
59
+ @options = {} unless @options
60
+ c = 0
61
+ for arg in args
62
+ value = args[c + 1] || ""
63
+ value = nil if value.include?("-")
64
+ @options[arg.gsub(/-/, "")] = value if arg.include?("-")
65
+ c += 1
66
+ end
67
+ size = @options.size * 2
68
+ args.slice!(0 - size, size)
69
+ end
70
+
71
+
72
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: key-installer
3
+ version: !ruby/object:Gem::Version
4
+ hash: 13
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ version: "1.1"
10
+ platform: ruby
11
+ authors:
12
+ - Adam Cooke
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-15 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description:
22
+ email: adam@atechmedia.com
23
+ executables:
24
+ - install-key
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - bin/install-key
31
+ - lib/key_installer.rb
32
+ - README.rdoc
33
+ has_rdoc: true
34
+ homepage: http://www.atechmedia.com
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Tiny utility to install SSH keys onto remote machines
67
+ test_files: []
68
+