MENU

溶けかけてるうさぎ HP GALLERY BLOG TOP RECENT ARTICLES POPULAR ARTICLES ABOUT THIS BLOG

CATEGORY

大学 (140) 仕事 (17) 航空宇宙 (104) 写真 (77) 旅行 (32) 飯・酒 (17) コンピュータ (118) その他 (44)

TAG

ARCHIVE

RECENT

【カメラ】X100 シリーズが好きすぎる(主にリーフシャッタ) 【カメラ】X100V から X100VI に買い替えました 【自宅サーバー】Google Domains から Cloudflare にドメインを移管 【カメラ】FUJIFILM XF レンズのサイズ比較ができるようにしてみた 【写真】自作写真閲覧ページにてフィルムシミュレーションで写真をフィルタできるようにした

【Ubuntu】Ubuntu ServerでのSSHポートフォワーディングとそのログ

事象発生日:2018-05-15

記事公開日:2018-05-15

アクセス数:9344

SSHポートフォワーディング用のサーバー構築もようやく終盤である.

SSHポートフォワーディングで接続できるかの確認と,転送先情報などのログ保存である.

1.環境

サーバー

Ubuntu Server 18.04 LTS

FUJITSU Server PRIMERGY TX1310 M3

4GB DDR4 x 1

2TB HDD x 1

 

Ubuntu Serverは「」で構築したものである.

さらに

で基本的なSSH設定を終えている.

クライアント

Microsoft Windows 10 Home 1803 (64bit)

CYGWIN_NT-10.0 2.9.0(0.318/5/3) 2017-09-12 10:18 x86_64 Cygwin

2.公開鍵認証でのSSHポートフォワーディング

CygwinなどのOpenSSHクライアントで,次のようにコマンドを打つと,localhostの${local_port}番ポートが${ssh_host}を踏み台にして${dest_ip}${dest_port}に転送される.

$ ssh -p ${ssh_port} -i ./.ssh/${key} ${ssh_user}@${ssh_host} -L ${local_port}:${dest_ip}:${dest_port}

なお,「」でやったようにCygwinの~/.ssh/configを設定しておけば,

$ ssh ${Label} -L ${local_port}:${dest_ip}:${dest_port}

と簡単に接続できる.

3.ポートフォワーディング先の情報などをログで残す

${dest_ip}${dest_port}をサーバー側でログに残せないか,sshdのログレベルをいじっていたところ,DEBUG1でいけることがわかった.

 

/etc/ssh/sshd_configを編集し,ログレベルを変更する.

$ diff /etc/ssh/sshd_config /etc/ssh/sshd_config.backup.20180515
27c27
< LogLevel DEBUG1
---
> LogLevel VERBOSE

SSHログインだけではログは残らないようだが,そのポートで通信すると以下のようなログが残った.

$ grep sshd auth.log
...
May 15 10:11:43 ${host} sshd[2346]: debug1: server_input_channel_open: ctype direct-tcpip rchan 3 win 2097152 max 32768
May 15 10:11:43 ${host} sshd[2346]: debug1: server_request_direct_tcpip: originator ::1 port 59776, target ${dest_ip} port ${dest_port}
May 15 10:11:43 ${host} sshd[2346]: debug1: connect_next: host ${dest_ip} ([${dest_ip}]:${dest_port}) in progress, fd=9
May 15 10:11:43 ${host} sshd[2346]: debug1: channel 1: new [direct-tcpip]
May 15 10:11:43 ${host} sshd[2346]: debug1: server_input_channel_open: confirm direct-tcpip
May 15 10:11:43 ${host} sshd[2346]: debug1: server_input_channel_open: ctype direct-tcpip rchan 4 win 2097152 max 32768
May 15 10:11:43 ${host} sshd[2346]: debug1: server_request_direct_tcpip: originator ::1 port 59777, target ${dest_ip} port ${dest_port}
May 15 10:11:43 ${host} sshd[2346]: debug1: connect_next: host ${dest_ip} ([${dest_ip}]:${dest_port}) in progress, fd=12
May 15 10:11:43 ${host} sshd[2346]: debug1: channel 2: new [direct-tcpip]
May 15 10:11:43 ${host} sshd[2346]: debug1: server_input_channel_open: confirm direct-tcpip
May 15 10:11:43 ${host} sshd[2346]: debug1: channel 1: connected to ${dest_ip} port ${dest_port}
May 15 10:11:43 ${host} sshd[2346]: debug1: channel 2: connected to ${dest_ip} port ${dest_port}
May 15 10:11:53 ${host} sshd[2346]: debug1: channel 1: free: direct-tcpip, nchannels 3
May 15 10:11:53 ${host} sshd[2346]: debug1: channel 2: free: direct-tcpip, nchannels 2
...

4.参考サイト

OpenSSH-7.3p1 日本語マニュアルページ (2016/10/15). SSHD_CONFIG (5). Retrieved May 15, 2018, from https://euske.github.io/openssh-jman/sshd_config.html

関連記事

コメントを投稿

名前

Email (※公開されることはありません)

コメント