Ubuntu 18.04 sharing files between shared folders and other systems

Background introduction

Due to work reasons, I often need to use two desktop computers, one with Ubuntu and the other with Windows. Sometimes I need to transfer something between the two machines. In the past, I always used a USB flash drive to transfer between the two computers. Copying is very troublesome; I also tried cloud disk, which is even more troublesome;

Since both computers are on the same LAN and their IPs are relatively fixed, it is very suitable to use the Samba file sharing function in the Linux system. I have been too lazy to configure it. I configured it today and I feel that the tutorials are a bit lacking and do not meet my requirements. Here Record your own process;

So the simple thing is to open a shared folder in the Ubuntu machine as a server. Other machines can access the shared folder. There are two ways according to the difficulty of the operation. Use it as you like.

Simple version

Let me first introduce a crude version of the method. This method is simple to operate and does not require instructions. It is suitable for casual use and novices. The goal is:

  • Any machine under the same LAN (taking win10 as an example) can access Ubuntu shared folders without obstruction;
  • Both win and Ubuntu can access, create and delete files, but they cannot modify files created by the other party;

1. \home\用户名\Create your shared folder under the path, name it here share, right-click -> Local Network Sharing

Insert image description here

  1. After clicking, you may be prompted that the shared service is not installed. Just follow the prompts to install it. Then after installation, just check as shown below. You can write or not a comment in it. Don't worry about the share name; select both of the following. (so anyone can access)

Insert image description here

slightly more complete version

The requirements are:

  • Two desktop computers with fixed IP under the same LAN (Ubuntu & Windows 10)
  • Win is required to access a folder in Ubuntu and perform operations such as reading, modifying, and creating in it;
  • It is required that the folder shared by Ubuntu can only be accessed by the machine with the specified IP, and cannot be accessed by other machines in the LAN (limit the client IP to prevent file leakage);

1. Create a shared folder

mkdir /home/<username>/share/

2. Modify configuration file

  • Open configuration file

    sudo gedit /etc/samba/smb.conf
    
  • Copy the following statement at the bottom of the configuration file and modify it according to your user name

    [share]
       comment = Ubuntu_share
       browseable = yes
       path = /home/<username>/share
       read only = no
    

    The first line [share]is the folder name; commentit is a note, write browseablewhatever you want; just select yes; paththe shared folder path; read only select no so that you can modify the files inside;

  • [global]Add the following sentence under the top field

       hosts allow = 192.168.1.151,192.168.1.168
       hosts deny = 0.0.0.0/0
    

    Among them, hosts allow the following is the IP that restricts access to the folder. As shown below
    Insert image description here

3. Set the external login account and password (the client win10 has to fill in the account password after logging in for the first time, and you do not need to log in again in the future, you can connect directly)

In the terminal, enter the command and follow the prompts to add the new account name and password.

 sudo  smbpasswd -a username

Then use the following command to restart the service

 sudo smbd reload

Notice:

  • The tutorial says 设定的用户名必须与系统的账户名相同, for example, my Ubuntu account name is wgk. When I performed this step, the username I added was wgk, and there is no password requirement.
  • In addition, if you don’t want to fix the IP and just want to use the account and password to access, you should just delete the limited IP part in step 2, but I haven’t tried it.

4. External access, take win10 as an example

  • Right click on My Computer and click映射网络驱动

Insert image description here

  • Fill in the IP address of the Ubuntu machine, followed by the shared folder name (directly, no need to write the address)

Insert image description here

  • Just enter the account password set on Ubuntu according to the prompts.

reference

  1. https://www.debugpoint.com/2020/01/guide-how-share-folder-between-ubuntu-linux-windows/

  2. https://help.ubuntu.com/community/Samba/SambaServerGuide?_ga=2.162411132.1596887212.1628509482-1462565621.1628509482#Samba_Server_Configuration_by_GUI

  3. https://ubuntu.com/tutorials/install-and-configure-samba#3-setting-up-samba

Guess you like

Origin blog.csdn.net/u012057432/article/details/119566894