-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-ssh.rb
More file actions
executable file
·65 lines (51 loc) · 1.12 KB
/
set-ssh.rb
File metadata and controls
executable file
·65 lines (51 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env ruby
# frozen_string_literal: true
SSH_DIR = "#{Dir.home}/.ssh"
CONFIG = "#{Dir.home}/.ssh/config"
GIT_HOSTS = %w[
gitea.com
codeberg.org
gitlab.com
salsa.debian.org
tangled.sh
github.com
bitbucket.org
git.code.sf.net
ssh.dev.azure.com
hf.co
].freeze
def gen_sshkey(host, type = "ed25519", quiet: true)
suffix = host.gsub(".", "-")
keyfile = "#{Dir.home}/.ssh/id_#{type}_#{suffix}"
pubfile = "#{Dir.home}/.ssh/id_#{type}_#{suffix}.pub"
already = File.exist?(keyfile)
if already
quiet = false
end
cmd = "ssh-keygen -t #{type} -f #{keyfile} -P ''"
if type == "rsa"
cmd = "ssh-keygen -t #{type} -b 4096 -f #{keyfile} -P ''"
end
puts cmd
quiet ? %x(#{cmd}) : system(cmd)
File.open(CONFIG, "a+") do |f|
if !already
f.write("Host #{host}\n IdentityFile #{keyfile}\n\n")
end
end
puts "------ #{pubfile}"
puts File.read(pubfile)
puts "------"
puts
end
if !Dir.exist?(SSH_DIR)
Dir.mkdir(SSH_DIR)
end
GIT_HOSTS.each do |host|
if host != "ssh.dev.azure.com"
gen_sshkey(host)
else
gen_sshkey(host, "rsa")
end
end
# gen_sshkey(GIT_HOSTS[4])