Realize file transfer between Windows and Linux through ssh protocol

Note: The scp command is based on ssh login. If Linux does not have ssh installed, file copying cannot be performed. Centos comes with its own installation.


1. In the Windows terminal,  connect to Linux through the ssh protocol to realize file transfer ( Windows even Linux ):

1. Win+r enter cmd to enter the windows terminal

2. Copy Windows files to Linux, or copy Linux files to Windows

# 复制 Windows 文件到 Linux
scp D:\data\1.txt [email protected]:/root/data
# 复制 Windows 目录到 Linux(记得加 -r)
scp -r D:\data [email protected]:/root/data

# 复制 Linux 文件到 Windows
scp [email protected]:/root/data/1.txt D:\data
# 复制 Linux 目录到 Windows(记得加 -r)
scp -r [email protected]:/root/data D:\data

3. Enter the Linux password, press Enter to confirm, and the file transfer is completed

4. [Expansion] You can also connect to a Linux terminal on Windows

# root是Linux的一个本地用户,192.168.88.161是Linux的ip地址
ssh [email protected]

 


2. On the Linux terminal,  connect to Windows through the ssh protocol to realize file transfer ( Linux to Windows ):

1. Make sure your Windows is logged in with a local account first, do not log in with a Microsoft account, otherwise don’t blame me if you can’t connect later. Page flow: WIN start button in the lower left corner of the screen→Settings→Account

2. Then click the WIN start button in the lower left corner of the screen→Settings→Applications→Optional functions

3. Optional features→add features (make sure OpenSSH client and server are installed)

4. Right-click the "My Computer" icon and click Manage

5. Make sure that the status of the two services in the figure is "Running" and the startup type is "Automatic"

6. Go back to the Linux terminal and try to copy the Linux local files to the Windows D drive

# 注意 admin@ 后跟的是你 Windows 的本地 IP 地址
# 不清楚 WIndows 的 IP 地址,可以在 Windows 终端输入 ipconfig,查看以太网的 IPV4 地址即可
scp /root/data/1.txt [email protected]:D:\data

7. Enter the login password of the Windows local account name ??? (the blogger’s is admin), press Enter to confirm, and the file transfer is completed. (If you don't know your Windows local account name, you can enter net user in the windows terminal to check it yourself.


3. On the Linux terminal,  connect to Linux through the ssh protocol to realize file transfer ( Linux even Linux ):

1. Send Linux1 files to Linux2

scp [email protected]:/root/1.txt [email protected]:/root

# 如果设置了Linux之间的免密登录,可这样写:
scp 192.168.88.161:///root/1.txt 192.168.88.162:///root

2. [Expansion] Copy the remote Window1 file to Windows2 in the Linux terminal. (too stupid haha)

# 复制windows1中xiaomin用户的D盘data文件夹下的1.txt,到windows2中laowang用户的D盘中
scp [email protected]:D:\data\1.txt [email protected]:D:

Guess you like

Origin blog.csdn.net/qq_17685725/article/details/123501015