OpenSSH : SSH ファイル転送 (SUSE)2025/10/15 |
|
SSH を利用して、暗号化通信によるセキュアなファイル転送をすることができます。 |
|
| [1] | SCP (Secure Copy) によるファイルコピーの例です。 |
|
# 書式 ⇒ scp [オプション] コピー元 コピー先
# ローカルホストの [test.txt] を リモートホスト [node01.srv.world] 上の [suse] ユーザーのホームディレクトリ直下へコピー suse@dlp:~> scp ./testfile.txt suse@node01.srv.world:~/ (suse@node01.srv.world) Password: testfile.txt 100% 5 4.2KB/s 00:00 # リモートホスト [node01.srv.world] 上の [/home/suse/test.txt] を ローカルホストのカレントディレクトリにコピー suse@dlp:~> scp suse@node01.srv.world:/home/suse/testfile.txt ./testfile2.txt (suse@node01.srv.world) Password: testfile.txt 100% 5 4.0KB/s 00:00 |
| [2] | SFTP (SSH File Transfer Protocol) によるファイル転送です。 SFTP サーバー機能は suseOS ではデフォルトで有効になっていますが、もし有効になっていない場合は [/etc/ssh/sshd_config] に [Subsystem sftp /usr/libexec/openssh/sftp-server] の行を追加して [sshd] をリロードしておきます。 |
|
# sftp [オプション] [ユーザー@ホスト名] suse@dlp:~> sftp suse@node01.srv.world (suse@node01.srv.world) Password: # ログインユーザーのパスワード Connected to node01.srv.world. sftp> # リモートのカレントディレクトリ表示 sftp> pwd Remote working directory: /home/suse # ローカルのカレントディレクトリ表示 sftp> !pwd /home/suse # リモートのカレントディレクトリのファイル一覧表示 sftp> ls -l drwxr-xr-x ? suse suse 0 Oct 15 10:24 testdir -rw-r--r-- ? suse suse 5 Oct 15 10:22 testfile.txt # ローカルのカレントディレクトリのファイル一覧表示 sftp> !ls -l total 8 -rw-r--r--. 1 suse suse 5 Oct 15 10:22 testfile2.txt -rw-r--r--. 1 suse suse 5 Oct 15 10:21 testfile.txt # ディレクトリ移動 sftp> cd testdir sftp> pwd Remote working directory: /home/suse/testdir # ローカルのファイルをリモートにリネームアップロード sftp> put testfile.txt testfile3.txt Uploading testfile.txt to /home/suse/testdir/testfile3.txt testfile.txt 100% 5 24.1KB/s 00:00 sftp> ls -l -rw-r--r-- ? suse suse 5 Oct 15 10:25 testfile3.txt # ローカルの複数ファイルをリモートに一括アップロード sftp> put *.txt Uploading testfile.txt to /home/suse/testdir/testfile.txt testfile.txt 100% 5 14.0KB/s 00:00 Uploading testfile2.txt to /home/suse/testdir/testfile2.txt testfile2.txt 100% 5 19.9KB/s 00:00 sftp> ls -l -rw-r--r-- ? suse suse 5 Oct 15 10:27 testfile.txt -rw-r--r-- ? suse suse 5 Oct 15 10:27 testfile2.txt -rw-r--r-- ? suse suse 5 Oct 15 10:25 testfile3.txt # リモートのファイルをローカルにリネームダウンロード sftp> get testfile.txt testfile4.txt Fetching /home/suse/testdir/testfile.txt to testfile4.txt testfile.txt 100% 5 11.8KB/s 00:00 # リモートの複数ファイルをローカルに一括ダウンロード sftp> get *.txt Fetching /home/suse/testdir/testfile.txt to testfile.txt testfile.txt 100% 5 16.3KB/s 00:00 Fetching /home/suse/testdir/testfile2.txt to testfile2.txt testfile2.txt 100% 5 15.7KB/s 00:00 Fetching /home/suse/testdir/testfile3.txt to testfile3.txt testfile3.txt 100% 5 17.2KB/s 00:00 # リモートのカレントディレクトリにディレクトリ作成 sftp> mkdir testdir2 sftp> ls -l drwxr-xr-x ? suse suse 0 Oct 15 10:28 testdir2 -rw-r--r-- ? suse suse 5 Oct 15 10:27 testfile.txt -rw-r--r-- ? suse suse 5 Oct 15 10:27 testfile2.txt -rw-r--r-- ? suse suse 5 Oct 15 10:25 testfile3.txt # リモートのカレントディレクトリ内のディレクトリ削除 sftp> rmdir testdir2 sftp> ls -l -rw-r--r-- ? suse suse 5 Oct 15 10:27 testfile.txt -rw-r--r-- ? suse suse 5 Oct 15 10:27 testfile2.txt -rw-r--r-- ? suse suse 5 Oct 15 10:25 testfile3.txt # リモートのファイル削除 sftp> rm testfile3.txt Removing /home/suse/testdir/testfile3.txt sftp> ls -l -rw-r--r-- ? suse suse 5 Oct 15 10:27 testfile.txt -rw-r--r-- ? suse suse 5 Oct 15 10:27 testfile2.txt # ![command] で任意のコマンド実行 sftp> !cat /etc/passwd root:x:0:0:root:/root:/bin/bash tftp:x:499:499:TFTP Account:/srv/tftpboot:/usr/sbin/nologin nobody:x:65534:65534:nobody:/var/lib/nobody:/usr/sbin/nologin man:x:13:62:Manual pages viewer:/var/lib/empty:/usr/sbin/nologin lp:x:498:498:Printing daemon:/var/spool/lpd:/usr/sbin/nologin messagebus:x:497:482:User for D-Bus:/run/dbus:/usr/sbin/nologin dnsmasq:x:496:481:dnsmasq:/var/lib/empty:/usr/sbin/nologin ..... ..... # 終了 sftp> quit |
| Sponsored Link |
|
|