Linux servers often need to download and upload data, and every time you have to use the SCP command, which is quite cumbersome. In order to simplify the operation, it was decided to set up SMB sharing on Linux so that the data can be managed in an SMB way.
"Special Reminder"
It is quite dangerous to use SMB sharing in a public network environment. Before using SMB, make sure that the current environment is important and secure.
"Preparation"
Operating system: Debian 12
"Installation & Deployment"
First of all, you need to install the SMB tool and use the cifs-utils protocol toolkit directly. Other users can also just install SMB tool commands. For convenience, use the root user for login operations. The servers are brand new and don't have a lot of tools installed. If your environment is ready, you can install the cifs-utils protocol toolkit directly.
"Install cifs-utils"
First, update and upgrade the packages in your system:
Install some commonly used tools:
When you're ready, you can start installing the cifs-utils protocol toolkit.
"Create/Set SMB Mount"
Next, you need to create/set up a folder for SMB mounting. Use the command sudo mkdir < path/folder> Create a mount folder. If you already have a folder, you can skip this step.
Then you need to set up an SMB user and password. Use sudo smbpasswd -a <username> to set the password for the smb userNote: This username must already exist in the server's passwd file before setting it. The password of the root user is directly set.
Next, you need to set the appropriate permissions for the folder. For convenience, directly set to 777 permissions. Set it up as you see fit.
Next, edit the Samba conf and add a directory:
sudo vim /etc/samba/smb.conf
Add the following at the end:
[share]
comment = Shared folder
path = /root/user/smb
browseable = no
guest ok = no
read only = no
create mask = 0777
directory mask = 0777
Thereinto:
[share] is the name of the shared folder and can be modified as needed.
comment is a comment and can be left unmodified.
path is the path to the shared folder, which should be the same as the path of the folder created in the second step.
If browseable is set to yes, the shared folder can be viewed on the network.
If guest ok is set to yes, authentication is not required to access the shared folder.
If read only is set to no, the shared folder can be written.
Create mask and directory mask are permission masks for files and folders, and a setting to 0777 indicates that all users have the highest permissions.
Save and exit when you're done.
"Restart Samba Service"
Use the following command to restart the Samba service:
sudo service smbd restart
At this point, the server's SMB share setup is complete. This server can be accessed via SMB using other devices.
Enter your username and password to log in successfully.
Select the folder you just created to successfully access the server's folder.
At this point, the setup of our server is complete.
"Extended Applications"
After the SMB is deployed, it is convenient to operate remotely, and you can also try more applications. The following are available for reference:
First, you can use intranet traversal to put a server with a public IP address in the same network environment as the intranet. Then, use SMB to mount the local NAS file system to the public server.
Mount a share: Use the command "sudo mount -t cifs //server/share /mnt/smb -o username=user,password=pass" to mount the share, where "server" is the name of the server where the share is located, "share" is the name of the share, "user" is the username required to log in to the share, and "pass" is the password.
Finally, if you install the downloader on the server, you can download things directly to the local NAS from the public server.
To set up auto-mount at startup, edit the "/etc/fstab" file and add a line to it: "//server/share /mnt/smb cifs username=user,password=pass 0 0"
给权限:在username=user,password=pass后面添加,gid=id,uid=id 0 0 "//server/share /mnt/smb cifs username=user,password=pass,gid=id,uid=id 0 0"
Once the above steps are completed, the SMB share will be mounted to the "/mnt/smb" directory and will be automatically mounted every time the system is booted.
Note: The reference source is from the Internet