csexton-ssh-keyput 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +28 -0
- data/VERSION.yml +4 -0
- data/bin/ssh-keyput +57 -0
- data/lib/runner.rb +58 -0
- data/lib/ssh_keyput.rb +33 -0
- data/test/ssh_keyput_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +60 -0
data/README.markdown
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
ssh-keyput
|
2
|
+
==========
|
3
|
+
|
4
|
+
Copies your ssh public key to a server.
|
5
|
+
|
6
|
+
Because <i>ssh user@hostname "echo `cat ~/.ssh/id_dsa.pub` >> ~/.ssh/authorized_keys"</i> is too hard to remember.
|
7
|
+
|
8
|
+
Since OS X does not have the handy "ssh-copy-id" bash script by default I wanted to add a gem that I could install easily to perform the same task.
|
9
|
+
|
10
|
+
Currently I depend on a number of unix commands (like ssh and ssh-keygen), but I am sure that much of this could be replace by ruby libraries (and then we could make this gem dependent on those) but this does what I need it to and I don't have to remember complicated command lines.
|
11
|
+
|
12
|
+
It is pronounced "ssssh-kaput."
|
13
|
+
|
14
|
+
INSTALL
|
15
|
+
=======
|
16
|
+
|
17
|
+
> sudo gem install csexton-ssh-keyput -s http://gems.github.com
|
18
|
+
|
19
|
+
USAGE
|
20
|
+
=====
|
21
|
+
|
22
|
+
> ssh-keyput user@example.com
|
23
|
+
|
24
|
+
|
25
|
+
COPYRIGHT
|
26
|
+
=========
|
27
|
+
|
28
|
+
Copyright (c) 2008 Christopher Sexton. See LICENSE for details.
|
data/VERSION.yml
ADDED
data/bin/ssh-keyput
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# == Synopsis
|
4
|
+
# SSH Key Put Utility
|
5
|
+
#
|
6
|
+
# == Usage
|
7
|
+
# ssh-keyput [options]
|
8
|
+
#
|
9
|
+
# For help see http://github.com/csexton/ssh-keyput
|
10
|
+
|
11
|
+
require 'optparse'
|
12
|
+
require "#{File.dirname(__FILE__)}/../lib/ssh_keyput"
|
13
|
+
|
14
|
+
kp = SshKeyPut.new
|
15
|
+
|
16
|
+
o = OptionParser.new do |opts|
|
17
|
+
|
18
|
+
opts.summary_width = 25
|
19
|
+
|
20
|
+
opts.banner = "ssh-keyput (#{kp.version})\n",
|
21
|
+
" usage: ssh-keyput [options...] [user@]hostname\n"
|
22
|
+
|
23
|
+
opts.separator "Configuration:"
|
24
|
+
|
25
|
+
opts.on('-v', '--version') do
|
26
|
+
puts "ssh-keyput version #{kp.version}\n\n"
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
opts.on('-h', '--help', "Print this message") do
|
30
|
+
puts "#{opts}\n"
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
opts.on('-G', '--generate', "Generate an rsa key by running 'ssh-keygen -t rsa'") do
|
34
|
+
system "ssh-keygen -t rsa"
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
opts.on('-KFILE', '--key-file FILE', "Use a specific key file. Default #{kp.key_file}") do |file|
|
38
|
+
kp.key_file = file
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
begin
|
46
|
+
o.parse!
|
47
|
+
kp.host = ARGV[0]
|
48
|
+
raise "Invalid Parameter" unless kp.host
|
49
|
+
|
50
|
+
kp.put_key
|
51
|
+
rescue => detail
|
52
|
+
puts detail
|
53
|
+
puts "#{o}"
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
|
57
|
+
|
data/lib/runner.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# == Synopsis
|
4
|
+
# SSH Key Put Utility
|
5
|
+
#
|
6
|
+
# == Usage
|
7
|
+
# ssh-keyput [options]
|
8
|
+
#
|
9
|
+
# For help see http://github.com/csexton/ssh-keyput
|
10
|
+
|
11
|
+
require 'optparse'
|
12
|
+
|
13
|
+
module SshKeyPut
|
14
|
+
VERSION = "0.0.1"
|
15
|
+
|
16
|
+
class Runner
|
17
|
+
def self.runner
|
18
|
+
#@keyput = SshKeyPut::Base.new
|
19
|
+
|
20
|
+
self.parse_options
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.parse_options
|
26
|
+
OptionParser.new do |opts|
|
27
|
+
|
28
|
+
opts.summary_width = 25
|
29
|
+
|
30
|
+
opts.banner = "ssh-keyput (#{SshKeyPut::VERSION})\n\n",
|
31
|
+
"usage: ssh-keyput [options...]\n",
|
32
|
+
|
33
|
+
opts.separator ""
|
34
|
+
opts.separator "Configuration:"
|
35
|
+
|
36
|
+
opts.on('-v', '--version') do
|
37
|
+
puts "ssh-keyput version (#{SshKeyPut::VERSION})\n\n"
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
opts.on('-h', '--help') do
|
41
|
+
#RDoc::usage() #exits app
|
42
|
+
puts "#{opts}\n"
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
opts.on('-V', '--verbose') do
|
46
|
+
puts "Verbose!"
|
47
|
+
end
|
48
|
+
opts.on('-r', '--generate') do
|
49
|
+
puts "Installing example .twitter_archive.yml to your home directory"
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
|
53
|
+
end.parse!
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
SshKeyPut::Runner.runner
|
data/lib/ssh_keyput.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'yaml'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
class SshKeyPut
|
8
|
+
|
9
|
+
attr_accessor :host, :key_file
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@key_file = "#{ENV["HOME"]}/.ssh/id_rsa.pub"
|
13
|
+
end
|
14
|
+
|
15
|
+
def version
|
16
|
+
v = YAML.load_file "#{File.dirname(__FILE__)}/../VERSION.yml"
|
17
|
+
"#{v[:major]}.#{v[:minor]}.#{v[:patch]}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def put_key
|
21
|
+
unless (File.exists? @key_file)
|
22
|
+
puts "No key found, please run ssh-keyput --generate to make one"
|
23
|
+
end
|
24
|
+
|
25
|
+
#read in the key
|
26
|
+
key_code = File.open(@key_file).read.strip
|
27
|
+
|
28
|
+
system "ssh #{@host} \"mkdir ~/.ssh 2>/dev/null; chmod 700 ~/.ssh; echo '#{key_code}' >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys\""
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: csexton-ssh-keyput
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Sexton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-23 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: TODO
|
17
|
+
email: csexton@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- README.markdown
|
26
|
+
- VERSION.yml
|
27
|
+
- bin/ssh-keyput
|
28
|
+
- lib/runner.rb
|
29
|
+
- lib/ssh_keyput.rb
|
30
|
+
- test/ssh_keyput_test.rb
|
31
|
+
- test/test_helper.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/csexton/ssh-keyput
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options:
|
36
|
+
- --inline-source
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 2
|
58
|
+
summary: ssh key put utility
|
59
|
+
test_files: []
|
60
|
+
|