direct_ssh 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/direct_ssh.rb +0 -0
- data/lib/direct_ssh/key_handler.rb +62 -23
- data/lib/direct_ssh/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f830d2885afb47efdda1ab0fb71717a1a520e8a1862c4c9091062b938e0e386
|
4
|
+
data.tar.gz: a047bd0d2a74fcb96bf5a9383fb57b0b42a977ce5725d10ca7e856cc16beb106
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec3fed44a476fa188d80941efdeb6b229852355764d00384d8c3eb178640448521a69a75e68ec2b243e1bde4f8f7b08c1a38104394bb01ac2f759123c5d6eae4
|
7
|
+
data.tar.gz: 0fa20e65151e8a2796aec8303d4e09d78e5f44e1bd113c0e6d63b089dfcbbfadd6a3a9a8b06b78cc808470870a56adb468070cdfd7f85af29aca68effce5face
|
data/lib/direct_ssh.rb
CHANGED
File without changes
|
@@ -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
|
|
@@ -32,11 +32,11 @@ module KeyHandler
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.create_ssh_files
|
35
|
-
FileUtils.
|
36
|
-
FileUtils.touch
|
37
|
-
FileUtils.touch
|
38
|
-
FileUtils.touch
|
39
|
-
FileUtils.touch
|
35
|
+
FileUtils.mkdir Dir.home + '/.ssh'
|
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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: direct_ssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xia Xiongjun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|