skm 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +23 -0
- data/README.md +39 -0
- data/bin/skm +147 -0
- data/lib/skm/version.rb +11 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzE3NzBlYzJlYTgwOTYyNTY4NjZmNWJiNDllYzhlNDY0NjQ3ZmZkNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MGYxNTI4MzJjNTE5ODhhN2RkZmNlMjI3MTZlMzEyYTI2NWUxMjFhNA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDAwODZiOGZkN2Q3ZDM1ZWY0ZjdiNGZkMTBhNGRhZDM0MTJiMWEzY2JiMTZj
|
10
|
+
ZTM2NzBiZTRjNGUxMDczMDdjNGQ0MGI1MTY0ZDU0Yjg4OTgwZmNmNGZkZGI4
|
11
|
+
ZjQ3YWI4NDM3MDZmOGE1OWIzZGE4YTY4NDFhNzkxMjUxY2JkNzM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YTQ4MGE2OWRhMGNlNjFhYjllMjc0ZmQ5Y2I4YTNhMjU3MTYwMjM0MmNmZmZm
|
14
|
+
Y2EwNDdjOTc5ZWZjZGQxYTNkOGYxODA4NGE1NWFiZGY1NDllNWZjNGI0ZWYy
|
15
|
+
NjljMDNjOTY0ZDNhMTNkYWViZTU0NjM3MWJhMGJhZTdiZDA4Mzg=
|
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2013 Hong Xu
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
14
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
15
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
16
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
17
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
18
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
19
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
20
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
21
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
22
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
23
|
+
POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# skm -- Ssh Key Manager
|
2
|
+
|
3
|
+
Skm is a tool to manage your multiple ssh keys.
|
4
|
+
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
Create a new key:
|
9
|
+
|
10
|
+
skm create my_new_key
|
11
|
+
|
12
|
+
Create a new key with comment:
|
13
|
+
|
14
|
+
skm create my_new_key -C "my@email.com"
|
15
|
+
|
16
|
+
Switch to another key:
|
17
|
+
|
18
|
+
skm use key_name
|
19
|
+
|
20
|
+
List all keys:
|
21
|
+
|
22
|
+
skm list
|
23
|
+
|
24
|
+
|
25
|
+
For example, first we create two keys:
|
26
|
+
|
27
|
+
skm create key1
|
28
|
+
skm create key2
|
29
|
+
|
30
|
+
Then we switch to `key1`:
|
31
|
+
|
32
|
+
skm use key1
|
33
|
+
|
34
|
+
After done some work, we could then switch to `key2`:
|
35
|
+
|
36
|
+
skm use key2
|
37
|
+
|
38
|
+
Use `skm --help` and `skm [command] --help` to read more.
|
39
|
+
|
data/bin/skm
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'trollop'
|
5
|
+
require 'skm/version'
|
6
|
+
|
7
|
+
HOME_DIR = ENV['HOME'].chomp '/'
|
8
|
+
|
9
|
+
if HOME_DIR == nil
|
10
|
+
puts '$HOME variable can not be obtained.'
|
11
|
+
exit 2
|
12
|
+
end
|
13
|
+
|
14
|
+
DOT_SSH_DIR = "#{HOME_DIR}/.ssh"
|
15
|
+
|
16
|
+
# create command
|
17
|
+
def cmd_create(argv, keys_dir)
|
18
|
+
# create a new ssh key under ~/.mul-ssh-keys/key-name directory
|
19
|
+
|
20
|
+
opts = Trollop::options do
|
21
|
+
|
22
|
+
banner <<-EOS
|
23
|
+
Ssh Key Manager
|
24
|
+
|
25
|
+
skm create new-key-name [args]
|
26
|
+
|
27
|
+
Args:
|
28
|
+
EOS
|
29
|
+
|
30
|
+
opt :comment, 'Comment of the new key. Could be your email address.', :short => '-C', :type => :string
|
31
|
+
opt :password, 'Ask for password of the newly generated key. Default is on. Use --no-password to avoid asking.',
|
32
|
+
:short => '-p', :defualt => true
|
33
|
+
opt :type, 'Type of ssh key, rsa or dsa.', :short => '-t', :default => 'rsa'
|
34
|
+
end
|
35
|
+
|
36
|
+
Trollop::die :type, 'Unrecognized type.' unless ['rsa', 'dsa'].include? opts[:type]
|
37
|
+
Trollop::die "Too few arguments for 'create' command." if argv.length == 0
|
38
|
+
|
39
|
+
name = argv[0]
|
40
|
+
|
41
|
+
# generate the new key
|
42
|
+
new_key_dir = "#{keys_dir}/#{name}"
|
43
|
+
FileUtils.mkdir_p new_key_dir
|
44
|
+
cmd_str = "ssh-keygen -t #{opts[:type].downcase} -f #{new_key_dir}/id_#{opts[:type].downcase}"
|
45
|
+
cmd_str += " -C #{opts[:comment]}" if opts[:comment] != nil
|
46
|
+
cmd_str += ' -N ""' unless opts[:password]
|
47
|
+
|
48
|
+
unless system cmd_str
|
49
|
+
exit 4
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# use command
|
54
|
+
def cmd_use(argv, keys_dir)
|
55
|
+
Trollop::options do
|
56
|
+
banner <<-EOS
|
57
|
+
Ssh Key Manager
|
58
|
+
|
59
|
+
skm use key-name
|
60
|
+
|
61
|
+
Args:
|
62
|
+
EOS
|
63
|
+
end
|
64
|
+
|
65
|
+
Trollop::die "Too few arguments for 'use' command." if argv.empty?
|
66
|
+
|
67
|
+
name = argv[0]
|
68
|
+
|
69
|
+
key_dir = "#{keys_dir}/#{name}"
|
70
|
+
|
71
|
+
# check for existence of the key
|
72
|
+
unless File.exists? "#{key_dir}/id_rsa" or File.exists? "#{key_dir}/id_dsa"
|
73
|
+
puts "Key #{name} doesn't exist."
|
74
|
+
exit 3
|
75
|
+
end
|
76
|
+
|
77
|
+
FileUtils.mkdir_p DOT_SSH_DIR
|
78
|
+
|
79
|
+
# backup current keys and copy the key we are about to use
|
80
|
+
['id_rsa', 'id_rsa.pub', 'id_dsa', 'id_dsa.pub'].each do |f|
|
81
|
+
FileUtils.mv "#{DOT_SSH_DIR}/#{f}", "#{DOT_SSH_DIR}/#{f}.bak", :force => true if File.exists? "#{DOT_SSH_DIR}/#{f}"
|
82
|
+
FileUtils.cp "#{key_dir}/#{f}", DOT_SSH_DIR if File.exists? "#{key_dir}/#{f}"
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
# list command
|
88
|
+
def cmd_list(argv, keys_dir)
|
89
|
+
Trollop::options do
|
90
|
+
banner <<-EOS
|
91
|
+
Ssh Key Manager
|
92
|
+
|
93
|
+
skm list key-name
|
94
|
+
|
95
|
+
Args:
|
96
|
+
EOS
|
97
|
+
end
|
98
|
+
Dir.foreach(keys_dir) do |f|
|
99
|
+
puts f if File.directory?("#{keys_dir}/#{f}") and f != '.' and f != '..' and
|
100
|
+
(File.exists? "#{keys_dir}/#{f}/id_rsa" or File.exists? "#{keys_dir}/#{f}/id_dsa")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
SUB_COMMANDS = %w(create list use)
|
105
|
+
global_opts = Trollop::options do
|
106
|
+
version "#{SshKeyManager::VERSION::STRING} (C) 2013 Hong Xu"
|
107
|
+
|
108
|
+
banner <<-EOS
|
109
|
+
Ssh Key Manager
|
110
|
+
|
111
|
+
skm [command] [args]
|
112
|
+
|
113
|
+
Available commands:
|
114
|
+
|
115
|
+
create Create a new ssh key
|
116
|
+
list List ssh keys
|
117
|
+
use Switch ssh keys
|
118
|
+
|
119
|
+
Use skm [command] --help for the help of the command.
|
120
|
+
|
121
|
+
Global args:
|
122
|
+
EOS
|
123
|
+
|
124
|
+
opt :skm_dir, 'Directory of skm files.', :short => '-s', :default => "#{HOME_DIR}/.skm"
|
125
|
+
|
126
|
+
stop_on SUB_COMMANDS
|
127
|
+
end
|
128
|
+
|
129
|
+
Trollop::die 'Use "skm --help" or "skm [command] --help" for help' if ARGV.empty? or ARGV[0] == 'help'
|
130
|
+
|
131
|
+
# directory of skm
|
132
|
+
skm_dir = global_opts[:skm_dir]
|
133
|
+
keys_dir = "#{skm_dir}/keys"
|
134
|
+
|
135
|
+
cmd = ARGV.shift # get the subcommand
|
136
|
+
|
137
|
+
case cmd
|
138
|
+
when 'create'
|
139
|
+
cmd_create(ARGV, keys_dir)
|
140
|
+
when 'use'
|
141
|
+
cmd_use(ARGV, keys_dir)
|
142
|
+
when 'list'
|
143
|
+
cmd_list(ARGV, keys_dir)
|
144
|
+
else
|
145
|
+
end
|
146
|
+
|
147
|
+
|
data/lib/skm/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: skm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hong Xu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: trollop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
description: ''
|
28
|
+
email: hong@topbug.net
|
29
|
+
executables:
|
30
|
+
- skm
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/skm
|
35
|
+
- lib/skm/version.rb
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
homepage: https://github.com/xuhdev/skm#readme
|
39
|
+
licenses:
|
40
|
+
- BSD
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.0.3
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Manage Multiple ssh keys
|
62
|
+
test_files: []
|