平衡点
2007/10/29
_ spml package for etch
呟きです. 気にしないで.
ようやっと終わった...
- ToDo メモ
- rdoc-f95 の置き場が group writable じゃないので置けませんメール.
- 手引き作成
- ディレクトリ整理
- stable -> codename, GPG key のメール.
[ツッコミを入れる]
2008/10/29
_ ssh でのポートフォワード
やりたい事は
localhost から gwhost を経由して remotehost へ接続
です. HostKeyAlias を使用します. とりあえず フォワードする Port は 30001 + SSH の番号とします.
/etc/hosts の編集
remotehost.forward という host が localhost を指すように設定します.
127.0.0.1 localhost remotehost.forward
.ssh/config の修正
以下の情報を追加
Host remote.forward ForwardAgent yes Port [30001 + remotehost の SSH の Port 番号] HostKeyAlias remotehost.remotedomain
接続時
実際に接続する際には以下の通り. この例では,
localhost:30023 <-> gwhost <-> remotehost:22
となる.
$ ssh -f -N -L 30023:remotehost.forward:22 gwhost $ ssh remotehost.forward (接続できる) $ scp remotehost.forward:orig.txt . (remotehost の orig.txt を手元に scp) $ scp test.txt remotehost.forward: (localhost の test.txt を remotehost へ scp)
最後に
最初に
$ ssh -f -N -L 30023:remotehost.forward:22 gwhost
を実行するのが面倒なので, 以下の ruby script を使用中.
#!/usr/bin/env ruby
ssh="/usr/bin/ssh"
gateway="gatewayhost.remotedomain"
config = ENV['HOME']+"/.ssh/config"
pidfile = "/tmp/create-gw.pid"
def str2hash(str)
@str = str
s = @str.split(/\:/)
h = {}
while ! s.empty?
h.store(s.shift, s.shift)
end
return h
end
def parseconf(config)
@config = config
conf = []
File.open(config){|f|
while src = f.gets("") do
if src =~/^Host.*forward$\n/
s = src.strip!.gsub!(/^\s\s/,"").gsub!(/\n/,":").gsub(/ /,":")
conf.push(str2hash(s))
end
end
}
return conf
end
def create_gateway(conf, ssh, gateway)
@conf = conf
@ssh = ssh
@gateway = gateway
@conf.each do |host|
port = host['Port']
hostkeyalias = host['HostKeyAlias']
system("#{@ssh}","-f","-N","-L","#{port}:#{hostkeyalias}:22","#{@gateway}")
end
end
def get_gateway_pid(ssh=nil)
@ssh = ssh ||= "/usr/bin/ssh"
return pids = `pgrep -f "#{@ssh} -f -N -L"`.split(/\n/)
end
opt = ARGV[0] ||= "create"
if opt == "create" or opt == "start" or opt == "init"
unless FileTest.exist?(pidfile)
create_gateway(parseconf(config), ssh, gateway)
pid = File.open(pidfile, 'w')
pid.puts(get_gateway_pid(ssh))
pid.close
end
elsif opt == "close" or opt == "exit" or opt == "stop"
File.read(pidfile).each do |pid|
Process.kill(9,pid.to_i)
end
File.delete(pidfile)
end
_ 12:00 からミーティングなのに
起きたら 11:38. タクシー使ってしまった...
[ツッコミを入れる]