Homepage: first publish of a full set of parts for the server
[mwamko.git] / script / ajaxterm_setup_files / username_for_ssh
blob1dc431859b9e84d2ff3c55fd8cab45315864530c
1 #!/usr/bin/env ruby
3 SSH = '/usr/bin/ssh'
4 host = ARGV[0]
6 raise 'Invalid Host' unless
7 host =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
9 print "username: "
10 username = $stdin.gets.chomp
14 if username =~ /^[0-9a-zA-Z_]+$/
16 # TODO: Errors produced by ssh client should be logged
18 # "host" is singular for a reason
19 known_host_file = "~/.ssh/#{host}_known_host"
21 # -t is to force a pseudo-tty allocation
22 system("#{SSH} -t -t -o UserKnownHostsFile=#{known_host_file} " +
23 "#{username}@#{host}")
24 else
25 puts "ERROR: Illegal username"
26 end
28 puts
29 puts
30 print "Press the return key to restart..."
31 $stdin.gets