ruby1.9.xで、Net::SSHを使ってIPv6でSSHするー
Net::SSHを使ってIPv6でつなごうとしたら、引数がおかしいがな!と怒られた時の対応メモ。
環境
2.x系を利用しました。
$ gem list *** LOCAL GEMS *** bigdecimal (1.1.0) io-console (0.3) json (1.5.4) minitest (2.5.1) net-sftp (2.0.5) net-ssh (2.3.0) rake (0.9.2.2) rdoc (3.9.4)
おこられた内容
# SSHのデバッグログを出す(:verbose=>:debug) # セッション接続 Net::SSH.start("fe80::XXXX:XXXX:XXXX:XXXX", "user", :password => "password", :verbose=>:debug) do |ssh| result = ssh.exec!("ls -l") puts result end # => D, [2012-03-30T09:12:32.962733 #3309] DEBUG -- net.ssh.transport.session[47ab2d8]: establishing connection tofe80::XXXX:XXXX:XXXX:XXXX:22 # => Invalid argument - connect(2)
えー、引数が違うの??
じゃあIPv4だとどうなの?
Net::SSH.start("XXX.XXX.XXX.XXX", "user", :password => "password") do |ssh| result = ssh.exec!("ls -l") puts result end # => D, [2012-03-30T09:21:29.412012 #3325] DEBUG -- net.ssh.transport.session[5090b0a]: establishing connection to XXX.XXX.XXX.XXX:22 # => D, [2012-03-30T09:21:29.416018 #3325] DEBUG -- net.ssh.transport.session[5090b0a]: connection established # => ... (以下ログが続く)
つながったー!!!!ええええ。
SSHを振り返る。
SSHDの設定がおかしいのかなー。
IPv6は拒否します!みたいな…
アクセス制御ファイル内容確認する。
$ cat /etc/hosts.deny # アクセス拒否ファイル # # hosts.deny This file describes the names of the hosts which are # *not* allowed to use the local INET services, as decided # by the '/usr/sbin/tcpd' server. # # The portmap line is redundant, but it is left to remind you that # the new secure portmap uses hosts.deny and hosts.allow. In particular # you should know that NFS uses portmap! $ cat /etc/hosts.allow # アクセス許可ファイル # # hosts.allow This file describes the names of the hosts which are # allowed to use the local INET services, as decided # by the '/usr/sbin/tcpd' server. #
結論:なんにもなかった。
そういえば、SSHの接続方法ってどんなのだっけ?とテキストを確認。
- IPv4の場合
$ ssh XXX.XXX.XXX.XXX
- IPv6の場合
$ ssh fe80::XXXX:XXXX:XXXX:XXXX%eth0
インターフェース指定してる…??
試してみる
# SSHのデバッグログを出す(:verbose=>:debug) # セッション接続 Net::SSH.start("fe80::XXXX:XXXX:XXXX:XXXX%eth0", "user", :password => "password", :verbose=>:debug) do |ssh| result = ssh.exec!("ls -l") puts result end # => D, [2012-03-30T09:21:29.412012 #3325] DEBUG -- net.ssh.transport.session[5090b0a]: establishing connection to fe80::XXXX:XXXX:XXXX:XXXX:22 # => D, [2012-03-30T09:21:29.416018 #3325] DEBUG -- net.ssh.transport.session[5090b0a]: connection established
うごいたー!!!!
教訓:APIの書式だけじゃなくって、コマンドの書式も確認してみよう