ssh-forever 0.1.0

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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Matt Wynne
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = ssh-forever
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Matt Wynne. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ssh-forever"
8
+ gem.summary = %Q{Smooth password-less SSH setup}
9
+ gem.description = %Q{Provides a replacement for the SSH command which automatically copies your public key while logging in}
10
+ gem.email = "matt@mattwynne.net"
11
+ gem.homepage = "http://github.com/mattwynne/ssh-forever"
12
+ gem.authors = ["Matt Wynne"]
13
+ gem.bindir = 'bin'
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/ssh-forever ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require 'ssh-forever'
5
+
6
+ login = ARGV[0]
7
+ SecureShellForever.run(login)
@@ -0,0 +1,63 @@
1
+ module SecureShellForever
2
+ class << self
3
+ def run(login)
4
+ unless File.exists?(public_key_path)
5
+ STDERR.puts "You do not appear to have a public key. I expected to find one at #{public_key_path}\n"
6
+ STDERR.print "Would you like me to generate one? [Y/n]"
7
+ result = STDIN.gets.strip
8
+ unless result == '' or result == 'y' or result == 'Y'
9
+ flunk %Q{Fair enough, I'll be off then. You can generate your own by hand using\n\n\tssh-keygen -t rsa}
10
+ end
11
+ generate_public_key
12
+ end
13
+ `ssh #{login} "#{remote_command}"`
14
+ puts "Your public key has been copied to the remote server. From now on you can just use plain old 'ssh'. Logging you in..."
15
+ exec "ssh #{login}"
16
+ end
17
+
18
+ def remote_command
19
+ commands = []
20
+ commands << 'mkdir -p ~/.ssh'
21
+ commands << 'chmod 700 ~/.ssh'
22
+ commands << 'touch ~/.ssh/authorized_keys'
23
+ commands << 'chmod 700 ~/.ssh/authorized_keys'
24
+ commands << "echo #{key} >> ~/.ssh/authorized_keys"
25
+ commands.join(' && ')
26
+ end
27
+
28
+ def key
29
+ `cat #{public_key_path}`
30
+ end
31
+
32
+ def generate_public_key
33
+ silence_stream(STDOUT) do
34
+ silence_stream(STDERR) do
35
+ pipe = IO.popen('ssh-keygen -t rsa', 'w')
36
+ 6.times do
37
+ pipe.puts "\n"
38
+ end
39
+ end
40
+ end
41
+
42
+ flunk("Unable to generate your public key.") unless File.exists?(public_key_path)
43
+ end
44
+
45
+ def flunk(message)
46
+ STDERR.puts message
47
+ exit 1
48
+ end
49
+
50
+ def public_key_path
51
+ File.expand_path('~/.ssh/id_rsa.pub')
52
+ end
53
+
54
+ def silence_stream(stream)
55
+ old_stream = stream.dup
56
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
57
+ stream.sync = true
58
+ yield
59
+ ensure
60
+ stream.reopen(old_stream)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,46 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ssh-forever}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Matt Wynne"]
12
+ s.date = %q{2009-08-16}
13
+ s.default_executable = %q{ssh-forever}
14
+ s.description = %q{Provides a replacement for the SSH command which automatically copies your public key while logging in}
15
+ s.email = %q{matt@mattwynne.net}
16
+ s.executables = ["ssh-forever"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "bin/ssh-forever",
28
+ "lib/ssh-forever.rb",
29
+ "ssh-forever.gemspec"
30
+ ]
31
+ s.homepage = %q{http://github.com/mattwynne/ssh-forever}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.4}
35
+ s.summary = %q{Smooth password-less SSH setup}
36
+
37
+ if s.respond_to? :specification_version then
38
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
42
+ else
43
+ end
44
+ else
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ssh-forever
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Wynne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-16 00:00:00 +01:00
13
+ default_executable: ssh-forever
14
+ dependencies: []
15
+
16
+ description: Provides a replacement for the SSH command which automatically copies your public key while logging in
17
+ email: matt@mattwynne.net
18
+ executables:
19
+ - ssh-forever
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .gitignore
27
+ - LICENSE
28
+ - README.rdoc
29
+ - Rakefile
30
+ - VERSION
31
+ - bin/ssh-forever
32
+ - lib/ssh-forever.rb
33
+ - ssh-forever.gemspec
34
+ has_rdoc: true
35
+ homepage: http://github.com/mattwynne/ssh-forever
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.3.4
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Smooth password-less SSH setup
62
+ test_files: []
63
+