.. _cloud_vds_transport_key: ====================================================================== 公開鍵認証を用いたバーチャルドメインサーバへのファイル転送 ====================================================================== .. contents:: :local: :depth: 2 バーチャルドメインサーバ `post-4 `_, `post-5 `_, `post-6 `_, `post-7 `_, `post-8 `_ のWWWサービスでは公開鍵による学外からSFTPによるファイル転送が可能です。 利用者が作成した公開鍵をバーチャルドメインサーバに配置することにより、 学外からSSLによるセキュアなファイル転送が可能になります。 公開鍵の作成、及びWindows(PuTTY,WinSCP)からバーチャルドメインサーバへファイルを転送する手順例をご案内します。ご参考ください。 1. 公開鍵の作成、バーチャルドメインサーバへの鍵の配置 ============================================================= 公開鍵の作成、作成した公開鍵をバーチャルドメインサーバに配置するための手順を以下に案内します。 ウェブブラウザにより,これらを管理(上記サービスに関わる登録・編集(パスワード変更を含む)・削除など)できます. ここではバーチャルドメインサーバ上の管理者アカウントを ``examplewww``, 管理者の `UECアカウント `_ を ``xa012345`` とし、 ご利用中のバーチャルドメインサーバは `post-4 `_ としています。 実際の利用環境に合わせて適宜読み替えてください。 .. _cloud_vds_transport_key-make-keypair: 1-1. 公開鍵・秘密鍵のペアの作成 ---------------------------------------------------------------------------- .. code-block:: bash [xa012345@sol ~]$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home3/staff/xa012345/.ssh/id_rsa): Created directory \'/home3/staff/xa012345/.ssh\'. Enter passphrase (empty for no passphrase): ... (パスフレーズを入力) Enter same passphrase again: ... (上と同じパスフレーズを入力) Your identification has been saved in /home3/staff/xa012345/.ssh/id_rsa. Your public key has been saved in /home3/staff/xa012345/.ssh/id_rsa.pub. The key fingerprint is: XX:XX:XX:6b:a1:1f:f0:f5:59:a8:12:0c:82:XX:XX:XX xa012345@sol.cc.uec.ac.jp The key\'s randomart image is: +--[ RSA 2048]----+ | | |.. | |... .E | | o.Oo + . | | . +. O S . . | | .= B + o | | . B . o | | o o | | . | +-----------------+ [xa012345@sol ~]$ cd ~/.ssh/ [xa012345@sol ~/.ssh]$ cp -p id_rsa id_rsa.ppk 作成された秘密鍵(~/.ssh/id_rsa,~/.ssh/id_rsa.ppk)をUSBメモリなどに保管し、実際にファイル転送で使用される端末にコピーします。 パスフレーズの内容はもちろん、 **秘密鍵も厳重に管理してください。** もし、秘密鍵を保存した機器を紛失、あるいはパスフレーズや秘密鍵自体が外部に漏れた(漏れた恐れがある)場合は、 **速やかに公開鍵、秘密鍵を変更してください。** ファイル id_rsa.ppk は、Windowsマシンで利用するファイルです。 もし、Windowsマシンからファイル転送を行う予定が無い場合は、作成は不要です。 .. _make-keyfilename: 1-2. 公開鍵のファイル名の変更 -------------------------------------------------------- バーチャルドメインサーバは、公開鍵を authorized_keys と言うファイル名で認識します。 そこで :ref:`cloud_vds_transport_key-make-keypair`_ で作成された公開鍵(id_rsa.pub)をリネームします。 .. code-block:: bash [xa012345@sol ~/.ssh]$ mv id_rsa.pub authorized_keys 1-3. 公開鍵をバーチャルドメインサーバへ配置 --------------------------------------------------------------------------- :ref:`make-keyfilename` で作成された公開鍵(authorized_keys)をバーチャルドメインサーバの .ssh ディレクトリにFTPにより転送します。 もし、バーチャルドメインサーバ上にディレクトリ .ssh が存在しない場合は、 `情報基盤センター `_ にお知らせください。 .. code-block:: bash [xa012345@sol ~/.ssh]$ ftp post-4 Connected to post-4 (130.153.8.9). 220 (vsFTPd 2.0.5) Name (post-4:xa012345): examplewww 331 Please specify the password. Password: ... (examplewww のパスワードを入力) 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> cd .ssh 250 Directory successfully changed. ftp> put authorized_keys local: authorized_keys remote: authorized_keys 227 Entering Passive Mode (130,153,8,9,226,54) 150 Ok to send data. 226 File receive OK. 407 bytes sent in 0.000333 secs (1222.22 Kbytes/sec) ftp> bye 221 Goodbye. 以上で公開鍵の設定は終了です。 次の手順により、教育系サーバ sol からSFTPによる接続が可能か確認してください。 1-4. バーチャルドメインサーバにSFTPで接続可能か確認 --------------------------------------------------------------------------------------- .. code-block:: bash [xa012345@sol ~]$ sftp examplewww@post-4.cc.uec.ac.jp Connecting to post-4.cc.uec.ac.jp... The authenticity of host \'post-4.cc.uec.ac.jp (130.153.8.9)\' can\'t be established. RSA key fingerprint is XX:XX:XX:2b:a8:89:68:e5:ce:46:60:66:7d:XX:XX:XX. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added \'post-4.cc.uec.ac.jp,130.153.8.9\' (RSA) to the list of known hosts. Enter passphrase for key \'/home3/staff/xa012345/.ssh/id_rsa\': ... sftp> ls cgi-bin html logs tmp sftp> cd html sftp> ls index.html sftp> bye 2. Windowsマシンでの接続の確認方法 ============================================================= PuTTY,WinSCPがインストールされたWindowsマシンのSFTPによる接続の方法についての手順を以下に案内します。 それ以外の環境の方は、利用される環境に合わせて適宜読み替えてください。 情報基盤センターの `教育系端末 `_ には、PuTTY,WinSCPのどちらもインストールされています。動作検証等にご利用ください。 なお、PuTTY,WinSCPの利用方法については、インターネット上の情報等をもとに対処してください。 .. _make-keywindows1: 2-1. 秘密鍵をSFTPクライアント(WinSCP)が利用できる形式へ変換 ---------------------------------------------------------------------------------------- 秘密鍵(id_rsa.ppk)を他のネットワーク機器とファイル共有されていないフォルダにコピーします。 ここでは便宜上、マイドキュメント直下に秘密鍵を置いたものとして説明しています。 .. figure:: imgs/2015-0907_Key_Authentication_Win01.png :width: 300pt :align: center PuTTY Key Generator(PuTTYgen)を起動し、「Load」ボタンをクリックしてPuTTYgenに秘密鍵を読み込ませます。 .. list-table:: :align: center :widths: 50 50 * - .. image:: imgs/2015-0907_Key_Authentication_Win02.png :width: 300pt - .. image:: imgs/2015-0907_Key_Authentication_Win03.png :width: 300pt パスフレーズを入力します。 .. figure:: imgs/2015-0907_Key_Authentication_Win04.png :width: 300pt :align: center 正しいパスフレーズを入力していれば秘密鍵が読み込まれますので、「Save private key」をクリックして秘密鍵を生成します。 .. list-table:: :align: center :widths: 50 50 * - .. image:: imgs/2015-0907_Key_Authentication_Win05.png :width: 300pt - .. image:: imgs/2015-0907_Key_Authentication_Win06.png :width: 300pt ここでは変換後の秘密鍵のファイル名を virtual_domain_server.ppk として保存しています。 .. figure:: imgs/2015-0907_Key_Authentication_Win07.png :width: 300pt :align: center 2-2. WinSCPの設定 ---------------------------------------- WinSCPを起動し、下の画像に従ってホスト名、ユーザ名を入力し、「設定」ボタンをクリックします。 .. figure:: imgs/2021-0208_Key_Authentication_Win08.png :width: 300pt :align: center 新たに表示された「高度なサイトの設定」ウインドウ左側の「認証」をクリックし、 グループ「認証条件」の秘密鍵に対し :ref:`make-keywindows1` の手順で作成した秘密鍵 virtual_domain_server.ppkを読み込みます。 .. list-table:: :align: center :widths: 50 50 * - .. image:: imgs/2015-0907_Key_Authentication_Win09.png :width: 300pt - .. image:: imgs/2015-0907_Key_Authentication_Win10.png :width: 300pt 初回アクセス時に、ホストキーに関するダイアログが表示されるため「はい」をクリックして処理を続行します。 パスフレーズを問い合わせるダイアログが表示されるので,:ref:`cloud_vds_transport_key-make-keypair` で設定したパスフレーズを入力します。 .. list-table:: :align: center :widths: 50 50 * - .. image:: imgs/2015-0907_Key_Authentication_Win11.png :width: 300pt - .. image:: imgs/2015-0907_Key_Authentication_Win12.png :width: 300pt 最後に「ログイン」ボタンをクリックし、問題が無ければファイル転送用のGUIが表示されます。 .. figure:: imgs/2021-0208_Key_Authentication_Win13.png :width: 300pt :align: center 3. 注意事項 ============================================================= 本サービスの利用に当たり、以下の注意事項があります。 - 公開鍵認証によるファイル転送は、WWWサービスのみ対応しています。 DNSサービスには提供していません。また、Mailサービスは仕組み上、提供する事ができません。 - バーチャルドメインサーバ上にディレクトリ .ssh が存在しない場合は、 `情報基盤センター `_ までメールでお知らせください。 - セキュリティ上の理由により、学外からFTPによるセキュアでないファイル転送はできません。 バーチャルドメインサーバに公開鍵を配置する作業は、学内ネットワーク上から行ってください。