Ubuntu and windows realize file sharing - use of Samba

foreword

(1) When we use Linux to develop, because writing programs in Linux is not as convenient as Windows tools, we often write programs in the windows environment first, and then upload the files to Linux for compilation.

(2) There is a problem in this way, because in the process of program writing, it is necessary to compile, report errors, check, and modify frequently. But because we write programs in the Windows environment, we need to upload them to Linux every time we compile and check, which feels very troublesome.

(3) So is there any way to allow us to write programs in the Windows environment, and then use them directly in Linux? Yes, that is the Samba I am going to introduce now.

(4) Note that before reading this article, you need to have the basics of using the Linux VIM editor, and the entry-level detailed tutorial of the Linux_vim editor ;

Samba configuration in Ubuntu environment

Install Samba

(1) First of all, we need to enter the following command to install. Note that it must be performed under root authority. So [sudo] password for topeet  will pop up afterwards : After that, we can enter the password we configured ourselves.

sudo apt-get install samba

(2) After that, during the installation process, it will suddenly get stuck, and Do you want to continue? [Y/n]  will appear . At this moment, we only need to enter y .

Modify the samba configuration file

(1) Root authority is still required, so you need to enter the following command.

(2) Because root authority is required, a request to enter a password may pop up, and you need to enter your own password. If you entered a password once before installing samba, you may not be asked to enter a password again.

sudo vi /etc/samba/smb.conf

(2) After entering the VIM editor, press and hold shift+g to enter the last line. Enter the following command on the last line.

(3) It should be noted that the comment after our # needs to be deleted. Otherwise errors may occur.

/********  解释  ********/
[ubuntu_samba]
    comment = arm ubuntu samba dir #说明
    path = /home/samba #共享的 samba #目录
    available = yes #允许访问
    browseable = yes #可以浏览
    public = yes #公开
    writable = yes #可写
    create mask = 0755 #当外部创建新文件时的权限
    security = share #共享模式
    force user = root #在外部添加新文件时, 文件的所有者
    arm force group =root #在外部添加新文件时, 文件的所在组

/********  实际写入  ********/
[ubuntu_samba]
    comment = arm ubuntu samba dir 
    path = /home/samba 
    available = yes
    browseable = yes 
    public = yes
    writable = yes 
    create mask = 0755 
    security = share 
    force user = root 
    arm force group =root 

(4) I do not recommend that you write the same as the following, because only the super user root has permission to operate the shared files below. Because operating under the root user is prone to problems, so I suggest making changes. Only need to change two places force user and arm force group .

(5) What are these two things? what's the function?

<1> First of all, let me introduce the force user. This is who the file owner is. Then we don’t want to attribute the file owner to root, but to ordinary users. How should we change it? First of all, we need to know what the common user is called. According to the picture below, we can know that the letter before @ indicates the currently logged in user name . Under normal circumstances, the user we log in directly is an ordinary user, so we need to change force user = root to force user = book. (Note, you need to change it yourself here!!!)

<2> What is the arm force group after? He indicates the group where the file is located, but how do we know the group where the file of ordinary users is located? It's very simple, after entering the common user name of groups , you can get the common user group.

 

(6) Now that we know the group and user name, can we write directly? NONONO, there are two more things to pay attention to: path and [ubuntu_samba] .

<1>path determines the folder that Ubuntu will share with windows. For example, we want to share the Ubuntu desktop with Windows, so that when we write files in Windows, they will directly appear on the Ubuntu desktop. So, path = /home/book/Desktop.

<2> And what is [ubuntu_samba]? This is related to the operations that need to be performed in Windows later. Let me mention it now, and you will know that you need to pay attention to it later.

 After file modification

(1) After modifying the file, enter: wq to exit VIM.

(2) Then restart samba, enter: sudo service smbd restart

What needs to be done in Windows

(1) Now we need to configure widows, but first we have to know the IP of Ubuntu. Enter ifconfig under Ubuntu, the first IP address needs to be remembered.

(2) Open This Computer in Windows -->\\+IP --> Enter

(3) Now we will get a folder ubuntu_samba. (Why I have three folders here, I will explain later)

(4) Right click --> Show more options --> Map network drive --> Finish.

(5) Finally, we turn on the computer, and the disk ubuntu_samba will appear in the network location. We write files in this disk, and after saving , Ubuntu will update in real time.

Create multiple shared paths

 (1) In many cases, it is impossible for us to share only one path. As you can see, I have shared several paths above. So what should we do to be able to share multiple paths?

(2) The steps are very simple, you only need to modify two places, the first is path, and its path is changed to the path you need to share. The second one is [ubuntu_samba], we can change it to any name, for example, if I change it to [ubuntu_samba_imx6ull], then the name of the shared file that appears on the network is ubuntu_samba_imx6ull.

(3) Finally, let me show you my configuration. As for when the share_directory folder was shared, I also forgot when it was. I was afraid that it would be used later, so I didn’t delete it.

[share_directory]

        path = /home/book

        available = yes

        public = yes

        guest ok = yes

        read only = no

        writeable = yes
[ubuntu_samba_imx6ull]
        comment = arm ubuntu samba dir
        path =  /home/book/nfs_rootfs
        available = yes
        browseable = yes
        public = yes
        writable = yes
        create mask = 0755
        security = share
        force user = book
        arm force group = book
[ubuntu_samba]
        comment = arm ubuntu samba dir
        path =  /home/book/Desktop
        available = yes
        browseable = yes
        public = yes
        writable = yes
        create mask = 0755
        security = share
        force user = book
        arm force group =book

Guess you like

Origin blog.csdn.net/qq_63922192/article/details/129927171