OpenSSH : SSH File Transfer (Rocky Linux)2021/07/19 |
It's possible to transfer files via SSH.
The follows is for Rocky Linux Clients,
but If you are using Windows 10 Version 1803 or later like here [8],
OpenSSH Client has been implemented as a Windows feature, so it's possible to use [scp], [sftp] commands like following examples
with the same usage on Windows PowerShell or Command Prompt, too.
|
|
[1] | It's the exmaple for using SCP (Secure Copy). |
# command ⇒ scp [Option] Source Target
# copy the [test.txt] on localhost to remote host [node01.srv.world] [rocky@dlp ~]$ scp ./test.txt rocky@node01.srv.world:~/ rocky@node01.srv.world's password: # password of the user test.txt 100% 10 0.0KB/s 00:00 # copy the [/home/rocky/test.txt] on remote host [node01.srv.world] to the localhost [rocky@dlp ~]$ scp rocky@node01.srv.world:/home/rocky/test.txt ./test.txt rocky@node01.srv.world's password: test.txt 100% 10 0.0KB/s 00:00 |
[2] | It's the examples to use SFTP (SSH File Transfer Protocol). SFTP server feature is enabled by default, but if not, enable it to add the line [Subsystem sftp /usr/libexec/openssh/sftp-server] in [/etc/ssh/sshd_config]. |
# sftp [Option] [user@host] [redhat@dlp ~]$ sftp rocky@node01.srv.world rocky@node01.srv.world's password: # password of the user Connected to prox.srv.world. sftp> # show current directory on remote host sftp> pwd Remote working directory: /home/rocky # show current directory on localhost sftp> !pwd /home/redhat # show files in current directory on remote host sftp> ls -l drwxrwxr-x 2 rocky rocky 7 Jul 16 21:33 public_html -rw-rw-r-- 1 rocky rocky 10 Jul 16 22:53 test.txt # show files in current directory on localhost sftp> !ls -l total 4 -rw-rw-r-- 1 redhat redhat 10 Jul 29 21:31 test.txt # change directory sftp> cd public_html sftp> pwd Remote working directory: /home/rocky/public_html # upload a file to remote host sftp> put test.txt redhat.txt Uploading test.txt to /home/rocky/redhat.txt test.txt 100% 10 0.0KB/s 00:00 sftp> ls -l drwxrwxr-x 2 rocky rocky 6 Jul 16 21:33 public_html -rw-rw-r-- 1 rocky rocky 10 Jul 16 21:39 redhat.txt -rw-rw-r-- 1 rocky rocky 10 Jul 16 22:53 test.txt # upload some files to remote host sftp> put *.txt Uploading test.txt to /home/rocky/test.txt test.txt 100% 10 0.0KB/s 00:00 Uploading test2.txt to /home/rocky/test2.txt test2.txt 100% 0 0.0KB/s 00:00 sftp> ls -l drwxrwxr-x 2 rocky rocky 6 Jul 16 21:33 public_html -rw-rw-r-- 1 rocky rocky 10 Jul 16 21:39 redhat.txt -rw-rw-r-- 1 rocky rocky 10 Jul 16 21:45 test.txt -rw-rw-r-- 1 rocky rocky 10 Jul 16 21:46 test2.txt # download a file from remote host sftp> get test.txt Fetching /home/rocky/test.txt to test.txt /home/rocky/test.txt 100% 10 0.0KB/s 00:00 # download some files from remote host sftp> get *.txt Fetching /home/rocky/redhat.txt to redhat.txt /home/rocky/redhat.txt 100% 10 0.0KB/s 00:00 Fetching /home/rocky/test.txt to test.txt /home/rocky/test.txt 100% 10 0.0KB/s 00:00 Fetching /home/rocky/test2.txt to test2.txt /home/rocky/test2.txt 100% 10 0.0KB/s 00:00 # create a directory on remote host sftp> mkdir testdir sftp> ls -l drwxrwxr-x 2 rocky rocky 6 Jul 16 21:33 public_html -rw-rw-r-- 1 rocky rocky 10 Jul 16 21:39 redhat.txt -rw-rw-r-- 1 rocky rocky 10 Jul 16 21:45 test.txt -rw-rw-r-- 1 rocky rocky 10 Jul 16 21:46 test2.txt drwxrwxr-x 2 rocky rocky 6 Jul 16 21:53 testdir # delete a directory on remote host sftp> rmdir testdir rmdir ok, `testdir' removed sftp> ls -l drwxrwxr-x 2 rocky rocky 6 Jul 16 21:33 public_html -rw-rw-r-- 1 rocky rocky 10 Jul 16 21:39 redhat.txt -rw-rw-r-- 1 rocky rocky 10 Jul 16 21:45 test.txt -rw-rw-r-- 1 rocky rocky 10 Jul 16 21:46 test2.txt # delete a file on remote host sftp> rm test2.txt Removing /home/rocky/test2.txt sftp> ls -l drwxrwxr-x 2 rocky rocky 6 Jul 16 21:33 public_html -rw-rw-r-- 1 rocky rocky 10 Jul 16 21:39 redhat.txt -rw-rw-r-- 1 rocky rocky 10 Jul 16 21:45 test.txt # execute commands with ![command] sftp> !cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin ... ... redhat:x:1001:1001::/home/redhat:/bin/bash # exit sftp> quit 221 Goodbye. |
Sponsored Link |