direct_ssh 0.1.8 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/bin/direct_ssh +1 -2
- data/direct_ssh.gemspec +17 -17
- data/lib/direct_ssh/key_handler.rb +61 -22
- data/lib/direct_ssh/version.rb +1 -1
- metadata +26 -27
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NGQ1OTk3YjM0MDg4ZjNlYjQyZDdjODM0MWFmYTFjMWJlMzM1ZTUzNQ==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ba1c3e2ba267144d1f487937d263c3a85e7ffb1d261a3f8d67bfe27d57fd3f98
|
4
|
+
data.tar.gz: 2484d5d0ba106029424be7f72d3bd571802bacedbbb868c339d03072eab8b20e
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZDgwNDYzNDZhYzU5MWNkM2Q3MWMzZDVmZTg1YmJlYTAyNzlmZDBhNzNlMzEy
|
11
|
-
OWQ5OGRhMmJmNWE4ZjkyMGVjNzI0Njk0YTVkZDQ3NjBkMGNlYmU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZDA1MmUyNjExN2M5OTBhZGI0MDJiNzIxNTEyZTllMDQ2OWI0ZDY4NWQ2M2Rm
|
14
|
-
ZWZhNGFiY2RhOWZkZWQ2ZjY4Mjk2ZWFiYTBjMTRhZDUwY2RhM2UzZWQ1N2Vk
|
15
|
-
NTQ5YjE1MDEyMGFlNjdkZmNjMDk1OTI3MzU1ZjEwZDM2NDNmMjk=
|
6
|
+
metadata.gz: b80618a834bdc9c1f8885c2564a6e8e43edd02c24a2fad1ec1f87fb92f1441f2f18679754e20e9a11b49f0bf9e3c1812d56e066a92a6a7dff7e90c268b748387
|
7
|
+
data.tar.gz: b7b938d32d68bbde55b346e61020b0f7515cc018cd5bd1786971659362e1016f517cd6dc2de36082dd81f956db91f0c98c5c5aca5ad8581634d278ea66da0578
|
data/bin/direct_ssh
CHANGED
@@ -24,8 +24,7 @@ def main(argv)
|
|
24
24
|
host, user, port = parse_args(argv)
|
25
25
|
|
26
26
|
DirectSsh.start(host, user, {:port => port}) { |ssh|
|
27
|
-
|
28
|
-
puts 'Direct SSH connected successfully'
|
27
|
+
system "ssh #{user}@#{host} -p #{port}"
|
29
28
|
}
|
30
29
|
rescue ArgumentError => e
|
31
30
|
$stderr.puts e.message
|
data/direct_ssh.gemspec
CHANGED
@@ -6,24 +6,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
6
6
|
require 'direct_ssh/version'
|
7
7
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
spec.name = "direct_ssh"
|
10
|
+
spec.version = DirectSsh::VERSION
|
11
|
+
spec.authors = ["Xia Xiongjun"]
|
12
|
+
spec.email = ["xxjapp@gmail.com"]
|
13
|
+
spec.description = %q{In order to use SSH or SCP without the need to enter password every time, this gem will create public/private ssh rsa keys if they do not exist and send public key to remote server automatically only if necessary.}
|
14
|
+
spec.summary = %q{Use SSH or SCP directly without the need to enter password every time}
|
15
|
+
spec.homepage = %q{https://github.com/xxjapp/direct_ssh}
|
16
|
+
spec.license = "MIT"
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
spec.add_runtime_dependency "net-ssh", "~> 5.2"
|
24
|
+
spec.add_runtime_dependency "net-scp", "~> 2.0"
|
25
|
+
spec.add_runtime_dependency "highline", "~> 2.0"
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
28
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
29
29
|
end
|
@@ -6,7 +6,7 @@ require 'base64'
|
|
6
6
|
|
7
7
|
module KeyHandler
|
8
8
|
def self.send_key_to_remote(ssh)
|
9
|
-
ssh_public_key = get_ssh_public_key
|
9
|
+
ssh_public_key = get_ssh_public_key.chomp
|
10
10
|
send_ssh_public_key_to_remote(ssh, ssh_public_key)
|
11
11
|
end
|
12
12
|
|
@@ -33,10 +33,10 @@ module KeyHandler
|
|
33
33
|
|
34
34
|
def self.create_ssh_files
|
35
35
|
FileUtils.mkdir_p Dir.home + '/.ssh'
|
36
|
-
FileUtils.touch
|
37
|
-
FileUtils.touch
|
38
|
-
FileUtils.touch
|
39
|
-
FileUtils.touch
|
36
|
+
FileUtils.touch Dir.home + '/.ssh/id_rsa'
|
37
|
+
FileUtils.touch Dir.home + '/.ssh/id_rsa.pub'
|
38
|
+
FileUtils.touch Dir.home + '/.ssh/authorized_keys'
|
39
|
+
FileUtils.touch Dir.home + '/.ssh/known_hosts'
|
40
40
|
end
|
41
41
|
|
42
42
|
# see: http://www.noah.org/wiki/SSH_public_keys
|
@@ -61,34 +61,73 @@ module KeyHandler
|
|
61
61
|
################################################################
|
62
62
|
# remote ssh key process
|
63
63
|
|
64
|
+
def self.is_windows?(ssh)
|
65
|
+
ssh.exec!("echo %os%").chomp != "%os%"
|
66
|
+
end
|
67
|
+
|
64
68
|
def self.send_ssh_public_key_to_remote(ssh, key)
|
69
|
+
is_win = is_windows?(ssh)
|
70
|
+
|
65
71
|
if !remote_file_exists?(ssh, '~/.ssh/authorized_keys')
|
66
|
-
remote_create_ssh_files(ssh)
|
67
|
-
remote_chmod_ssh_files(ssh)
|
72
|
+
remote_create_ssh_files(ssh, is_win)
|
73
|
+
remote_chmod_ssh_files(ssh, is_win)
|
68
74
|
end
|
69
75
|
|
70
|
-
|
71
|
-
ssh.exec!("echo '#{key}' >> ~/.ssh/authorized_keys")
|
76
|
+
remote_append_key(ssh, key, is_win)
|
72
77
|
end
|
73
78
|
|
74
79
|
def self.remote_file_exists?(ssh, path)
|
75
|
-
|
80
|
+
# windows & linux OK
|
81
|
+
# path including '~/' OK
|
82
|
+
ssh.exec!("[ ! -f #{path} ] && echo NOT_EXIST").empty?
|
76
83
|
end
|
77
84
|
|
78
|
-
def self.remote_create_ssh_files(ssh)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
85
|
+
def self.remote_create_ssh_files(ssh, is_win)
|
86
|
+
if is_win
|
87
|
+
ssh_exec!(ssh, 'mkdir .ssh')
|
88
|
+
ssh_exec!(ssh, 'touch .ssh\id_rsa')
|
89
|
+
ssh_exec!(ssh, 'touch .ssh\id_rsa.pub')
|
90
|
+
ssh_exec!(ssh, 'touch .ssh\authorized_keys')
|
91
|
+
ssh_exec!(ssh, 'touch .ssh\known_hosts')
|
92
|
+
else
|
93
|
+
ssh_exec!(ssh, 'mkdir ~/.ssh')
|
94
|
+
ssh_exec!(ssh, 'touch ~/.ssh/id_rsa')
|
95
|
+
ssh_exec!(ssh, 'touch ~/.ssh/id_rsa.pub')
|
96
|
+
ssh_exec!(ssh, 'touch ~/.ssh/authorized_keys')
|
97
|
+
ssh_exec!(ssh, 'touch ~/.ssh/known_hosts')
|
98
|
+
end
|
84
99
|
end
|
85
100
|
|
86
101
|
# see: http://www.noah.org/wiki/SSH_public_keys
|
87
|
-
def self.remote_chmod_ssh_files(ssh)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
102
|
+
def self.remote_chmod_ssh_files(ssh, is_win)
|
103
|
+
if is_win
|
104
|
+
# puts "NOTE 1: The default mode on windows should work"
|
105
|
+
# puts "NOTE 2: 'chmod' is not available or doesn't work on windows."
|
106
|
+
# puts " If password asked, try to handle according to"
|
107
|
+
# puts " https://social.technet.microsoft.com/Forums/Azure/en-US/e4c11aed-1d8b-4ff4-89ad-c90c62e13ce0/ssh-asking-for-password-even-i-have-private-key"
|
108
|
+
# puts " and log file C:\\ProgramData\\ssh\\logs\\sshd.log"
|
109
|
+
else
|
110
|
+
ssh_exec!(ssh, 'chmod 700 ~/.ssh')
|
111
|
+
ssh_exec!(ssh, 'chmod 600 ~/.ssh/id_rsa')
|
112
|
+
ssh_exec!(ssh, 'chmod 644 ~/.ssh/id_rsa.pub')
|
113
|
+
ssh_exec!(ssh, 'chmod 644 ~/.ssh/authorized_keys')
|
114
|
+
ssh_exec!(ssh, 'chmod 644 ~/.ssh/known_hosts')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# append public_key to remote '~/.ssh/authorized_keys'
|
119
|
+
def self.remote_append_key(ssh, key, is_win)
|
120
|
+
if is_win
|
121
|
+
ssh_exec!(ssh, "echo #{key} >> .ssh\\authorized_keys")
|
122
|
+
else
|
123
|
+
ssh_exec!(ssh, "echo #{key} >> ~/.ssh/authorized_keys")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.ssh_exec!(ssh, cmd)
|
128
|
+
# puts "# #{cmd}"
|
129
|
+
res = ssh.exec! cmd
|
130
|
+
# puts res.force_encoding('SJIS').encode('UTF-8')
|
131
|
+
res
|
93
132
|
end
|
94
133
|
end
|
data/lib/direct_ssh/version.rb
CHANGED
metadata
CHANGED
@@ -1,85 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: direct_ssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xia Xiongjun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2
|
19
|
+
version: '5.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2
|
26
|
+
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: net-scp
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: highline
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '2.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '2.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1
|
61
|
+
version: '2.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1
|
68
|
+
version: '2.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
75
|
+
version: '13.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
82
|
+
version: '13.0'
|
83
83
|
description: In order to use SSH or SCP without the need to enter password every time,
|
84
84
|
this gem will create public/private ssh rsa keys if they do not exist and send public
|
85
85
|
key to remote server automatically only if necessary.
|
@@ -92,7 +92,7 @@ executables:
|
|
92
92
|
extensions: []
|
93
93
|
extra_rdoc_files: []
|
94
94
|
files:
|
95
|
-
- .gitignore
|
95
|
+
- ".gitignore"
|
96
96
|
- Gemfile
|
97
97
|
- LICENSE.txt
|
98
98
|
- README.md
|
@@ -115,17 +115,16 @@ require_paths:
|
|
115
115
|
- lib
|
116
116
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
|
-
- -
|
118
|
+
- - ">="
|
119
119
|
- !ruby/object:Gem::Version
|
120
120
|
version: '0'
|
121
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
|
-
|
128
|
-
rubygems_version: 2.4.8
|
127
|
+
rubygems_version: 3.1.4
|
129
128
|
signing_key:
|
130
129
|
specification_version: 4
|
131
130
|
summary: Use SSH or SCP directly without the need to enter password every time
|