Merge pull request #9206 from MjSeven/master

20180424 How to share files between Linux and Windows.md 翻译完毕
This commit is contained in:
Xingyu.Wang 2018-06-19 23:27:12 +08:00 committed by GitHub
commit 260a30fe36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 107 additions and 111 deletions

View File

@ -1,111 +0,0 @@
Translating by MjSeven
How to share files between Linux and Windows
======
![](https://images.idgesg.net/images/article/2018/04/cats-eating-100755724-large.jpg)
Many people today work on mixed networks, with both Linux and Windows systems playing important roles. Sharing files between the two can be critical at times and is surprisingly easy with the right tools. With fairly little effort, you can copy files from Windows to Linux or Linux to Windows. In this post, we'll look at what is needed to configure your Linux and Windows system to allow you to easily move files from one OS to the other.
### Copying files between Linux and Windows
The first step toward moving files between Windows and Linux is to download and install a tool such as PuTTY's pscp. You can get PuTTY from [putty.org][1] and set it up on your Windows system easily. PuTTY comes with a terminal emulator (putty) as well as tools like **pscp** for securely copying files between Linux and Windows systems. When you go to the PuTTY site, you can elect to install all of the tools or pick just the ones you want to use by choosing either the installer or the individual .exe files.
You will also need to have ssh-server set up and running on your Linux system. This allows it to support the client (Windows side) connection requests. If you don't already have an ssh server set up, the following steps should work on Debian systems (Ubuntu, etc.).
```
sudo apt update
sudo apt install ssh-server
sudo service ssh start
```
For Red Hat and related Linux systems, use similar commands:
```
sudo yum install openssh-server
sudo systemctl start sshd
```
Note that if you are running a firewall such as ufw, you may have to open port 22 to allow the connections.
Using the **pscp** command, you can then move files from Windows to Linux or vice versa. The syntax is quite straightforward with its "copy from to" commands.
#### Windows to Linux
In the command shown below, we are copying a file from a user's account on a Windows system to the /tmp directory on the Linux system.
```
C:\Program Files\PuTTY>pscp \Users\shs\copy_me.txt shs@192.168.0.18:/tmp
shs@192.168.0.18's password:
copy_me.txt | 0 kB | 0.1 kB/s | ETA: 00:00:00 | 100%
```
#### Linux to Windows
Moving the files from Linux to Windows is just as easy. Just reverse the arguments.
```
C:\Program Files\PuTTY>pscp shs@192.168.0.18:/tmp/copy_me.txt \Users\shs
shs@192.168.0.18's password:
copy_me.txt | 0 kB | 0.1 kB/s | ETA: 00:00:00 | 100%
```
The process can be made a little smoother and easier if 1) pscp is in your Windows search path and 2) your Linux system is in your Windows hosts file.
#### Windows search path
If you install the PuTTY tools with the PuTTY installer, you will probably find that **C:\Program files\PuTTY** is on your Windows search path. You can check to see if this is the case by typing **echo %path%** in a Windows command prompt (type "cmd" in the search bar to open the command prompt). If it is, you don't need to be concerned with where you are in the file system relative to the pscp executable. Moving into the folder containing the files you want to move will likely prove easier.
```
C:\Users\shs>pscp copy_me.txt shs@192.168.0.18:/tmp
shs@192.168.0.18's password:
copy_me.txt | 0 kB | 0.1 kB/s | ETA: 00:00:00 | 100%
```
#### Updating your Windows hosts file
Here's the other little fix. With administrator rights, you can add your Linux system to the Windows host file (C:\Windows\System32\drivers\etc\hosts) and then use the host name in place of its IP address. Keep in mind that this will not work indefinitely if the IP address on your Linux system is dynamically assigned.
```
C:\Users\shs>pscp copy_me.txt shs@stinkbug:/tmp
shs@192.168.0.18's password:
hosts | 0 kB | 0.8 kB/s | ETA: 00:00:00 | 100%
```
Note that Windows host files are formatted like the /etc/hosts file on Linux systems — IP address, white space and host name. Comments are prefaced with pound signs.
```
# Linux systems
192.168.0.18 stinkbug
```
#### Those pesky line endings
Keep in mind that lines in text files on Windows end with both a carriage return and a linefeed. The pscp tool will not remove the carriage returns to make the files look like Linux text files. Instead, it simply copies the files intact. You might consider installing the **tofrodos** package to enable you to use the **fromdos** and **todos** commands on your Linux system to adjust the files you are moving between platforms.
### Sharing folders between Windows and Linux
Sharing folders is an entirely different operation. You end up mounting a Windows directory on your Linux system or a Linux directory on your Windows box so that both systems can use the same set of files rather than copying the files from one system to the other. One of the best tools for this is Samba, which emulates Windows protocols and runs on the Linux system.
Once Samba is installed, you will be able to mount a Linux folder on Windows or a Windows folder on Linux. This is, of course, very different than copying files as described earlier in this post. Instead, each of the two systems involved will have access to the same files at the same time.
More tips on choosing the right tool for sharing files between Linux and Windows systems are available [here][2].
Join the Network World communities on [Facebook][3] and [LinkedIn][4] to comment on topics that are top of mind.
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3269189/linux/sharing-files-between-linux-and-windows.html
作者:[Sandra Henry-Stocker][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.networkworld.com/author/Sandra-Henry_Stocker/
[1]:https://www.putty.org
[2]:https://www.infoworld.com/article/2617683/linux/linux-moving-files-between-unix-and-windows-systems.html
[3]:https://www.facebook.com/NetworkWorld/
[4]:https://www.linkedin.com/company/network-world

View File

@ -0,0 +1,107 @@
如何在 Linux 和 Windows 之间共享文件?
=====
![](https://images.idgesg.net/images/article/2018/04/cats-eating-100755724-large.jpg)
现代很多人都在混合网络上工作Linux 和 Windows 系统都扮演着重要的结束。在两者之间共享文件有时是非常关键的,并且使用正确的工具非常容易。只需很少的功夫,你就可以将文件从 Windows 复制到 Linux 或从 Linux 到 Windows。在这篇文章中我们将讨论配置 Linux 和 Windows 系统所需的东西,以允许你轻松地将文件从一个操作系统转移到另一个。
### 在 Linux 和 Windows 之间复制文件
在 Windows 和 Linux 之间移动文件的第一步是下载并安装诸如 PuTTY 的 pscp 之类的工具。你可以从 [putty.org][1] 获得它,并轻松将其设置在 Windows 系统上。PuTTY 带有一个终端仿真器putty以及像 **pscp** 这样的工具,用于在 Linux 和 Windows 系统之间安全地复制文件。当你进入 PuTTY 站点时,你可以选择安装所有工具,或选择安装你想要的工具,也可以选择单个 .exe 文件。
你还需要在你的 Linux 系统上设置并运行 ssh-server。这允许它支持客户端Windows 端)连接请求。如果你还没有安装 ssh 服务器,那么以下步骤可以在 Debian 系统上运行(包括 Ubuntu 等):
```
sudo apt update
sudo apt install ssh-server
sudo service ssh start
```
对于 Red Hat 及其相关的 Linux 系统,使用类似的命令:
```
sudo yum install openssh-server
sudo systemctl start sshd
```
注意,如果你正在运行防火墙(例如 ufw则可能需要打开 22 端口以允许连接。
使用 **pscp** 命令,你可以将文件从 Windows 移到 Linux反之亦然。它的 “copy from to” 命令的语法非常简单。
#### 从 Windows 到 Linux
在下面显示的命令中,我们将 Windows 系统上用户账户中的文件复制到 Linux 系统下的 /tmp 目录。
```
C:\Program Files\PuTTY>pscp \Users\shs\copy_me.txt shs@192.168.0.18:/tmp
shs@192.168.0.18's password:
copy_me.txt | 0 kB | 0.1 kB/s | ETA: 00:00:00 | 100%
```
#### 从 Linux 到 Windows
将文件从 Linux 转移到 Windows 也同样简单。只要反向参数即可。
```
C:\Program Files\PuTTY>pscp shs@192.168.0.18:/tmp/copy_me.txt \Users\shs
shs@192.168.0.18's password:
copy_me.txt | 0 kB | 0.1 kB/s | ETA: 00:00:00 | 100%
```
如果 1) pscp 位于 Windows 搜索路径中,并且 2) 你的 Linux 系统在 Windows hosts 文件中则该过程可以变得更加顺畅和轻松。to 校正者:这句话不怎么明白)
#### Windows 搜索路径
如果你使用 PuTTY 安装程序安装 PuTTY 工具,你可能会发现 **C:\Program files\PuTTY** 位于 Windows 搜索路径中。你可以通过在 Windows 命令提示符下键入 **echo %path%** 来检查是否属于这种情况(在搜索栏中键入 “cmd” 来打开命令提示符)。如果是这样,你不需要关心文件系统中相对于 pscp 可执行文件的位置。进入到包含你想要移动文件的文件夹可能会更容易。
```
C:\Users\shs>pscp copy_me.txt shs@192.168.0.18:/tmp
shs@192.168.0.18's password:
copy_me.txt | 0 kB | 0.1 kB/s | ETA: 00:00:00 | 100%
```
#### 更新你的 Windows hosts 文件
这是另一个小修补。使用管理员权限,你可以将 Linux 系统添加到 Windows hosts 文件C:\Windows\System32\drivers\etc\hosts然后使用其主机名代替其 IP 地址。请记住,如果你的 Linux 系统的 IP 地址是动态分配的,那么它不会一直发挥作用。
```
C:\Users\shs>pscp copy_me.txt shs@stinkbug:/tmp
shs@192.168.0.18's password:
hosts | 0 kB | 0.8 kB/s | ETA: 00:00:00 | 100%
```
请注意Windows hosts 文件与 Linux 系统上的 /etc/hosts 文件格式相同 -- IP 地址,空格,主机名。注释以 poundto 校正者:这个符号是英镑符??) 符号来表示的。
```
# Linux systems
192.168.0.18 stinkbug
```
#### 讨厌的行结尾符
请记住Windows 上文本文件中的行以回车符和换行符结束。pscp 工具不会删除回车符,使文件看起来像 Linux 文本文件。相反,它只是完整地复制文件。你可以考虑安装 **tofrodos** 包,这使你能够在 Linux 系统上使用 **fromdos****todos** 命令来调整在平台之间移动的文件。
### 在 Windows 和 Linux 之间共享文件夹
共享文件夹是完全不同的操作。你最终将 Windows 文件夹挂载到你的 Linux 系统或将 Linux 文件夹挂载到 Windows 文件夹中,以便两个系统可以使用同一组文件,而不是将文件从一个系统复制到另一个系统。最好的工具之一就是 Samba它模拟 Windows 协议并在 Linux 系统上运行。
一旦安装了 Samba你将能够将 Linux 文件夹挂载到 Windows 上或将 Windows 文件夹挂载到 Linux 上。当然,这与本文前面描述的复制文件有很大的不同。相反,这两个系统中的每一个都可以同时访问相同的文件。
关于选择在 Linux 和 Windows 系统之间共享文件的正确工具的更多提示可以在[这里][2]找到。
在 [Facebook][3] 和 [LinkedIn][4] 上加入网络世界社区,对最重要的话题发表评论。
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3269189/linux/sharing-files-between-linux-and-windows.html
作者:[Sandra Henry-Stocker][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[MjSeven](https://github.com/MjSeven)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.networkworld.com/author/Sandra-Henry_Stocker/
[1]:https://www.putty.org
[2]:https://www.infoworld.com/article/2617683/linux/linux-moving-files-between-unix-and-windows-systems.html
[3]:https://www.facebook.com/NetworkWorld/
[4]:https://www.linkedin.com/company/network-world