[Linux] Build Samba server (ubuntu16.04)

Original article http://blog.csdn.net/humanking7/https://blog.csdn.net/humanking7/article/details/83796786

Article Directory

2018.12.17 Add:
New: [Linux]Samba server supports access to soft connection files and directories:https://blog.csdn.net/humanking7/article/details/85058471

1. Samba software installation and uninstallation#

1.1. installation##

apt-get install samba samba-common
# or
aptitude install -y samba

1.2. Uninstall##

apt-get autoremove samba

1.3. Check the Samb version##

method 1:

root@HP-xw4600:~# smbd --version
Version 4.3.11-Ubuntu

**Method 2: **

root@HP-xw4600:~# smbstatus
Samba version 4.3.11-Ubuntu
PID     Username      Group         Machine            Protocol Version       
------------------------------------------------------------------------------

Service      pid     machine       Connected at
-------------------------------------------------------

No locked files

1.4. Check and start Samba service##

Check if Samba service is running

systemctl status smbd
systemctl status nmbd

To start these two services

systemctl start smbd
systemctl start nmbd

After it starts running, smbd will listen on ports 139 and 445.

2. Preparation before configuration#

2.1. Create Samba Access Directory##

Create a samba access directory and increase the permissions of the directory

mkdir /srv/qfxFtp/HDD_sdb1/qfxSamba_share
chmod 777/srv/qfxFtp/HDD_sdb1/qfxSamba_share

I mounted the hard disk under the HDD_sdb1 directory, and the entire qfxFtp directory is the directory of the FTP server, but the permissions are read-only.

2.2. Create user account##

By default, Samba sets the user to safe mode, which means that the client must enter the user name and password of the shared folder.

Simply put: The added Samba user must first be a Linux user, so you have to create a new Linux user first. You can also use your original user as long as you are not afraid of leaking account information.

To add a user on Ubuntu, please run the following command (when I add a user, for safety, the user cannot log in). Replace the user name with the user name you need. I named it qfxsamba here (the original name was named qfxSamba, where S is uppercase, how to add the name is wrong, and finally look at the prompt carefully, and then I know that there is a problem with the naming , But what's wrong with the naming?)

adduser -s /sbin/nologin qfxsamba

2.3. Add user to samba service (the user just created)

smbpasswd  -a   qfxsamba  #[Enter the password to access Samba,Not a qfxsamba user password]

**PS: Common methods of **smbpasswd command:

smbpasswd -a Add users (the users to be added must be system users)
smbpasswd -d Freeze the user, that is, the user cannot log in
smbpasswd -e Restore users, unfreeze users, so that frozen users can use
smbpasswd -n Set the user's password to blank.
    To write null passwords in global-true
smbpasswd -x delete user

3. Edit configuration file#

Only one configuration file needs to be processed: /etc/samba/smb.conf

First develop a good habit of backup, and then edit with Vim:

cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
vim /etc/samba/smb.conf

The following is the part to be modified

[ global]
# Make sure that the value of the workgroup is the same as the workgroup setting of the Windows computer
 workgroup = WORKGROUP

# =====================================
#   add by Qfx
# =====================================
# " Qfx Share Dir"Is the folder name that will be displayed on the Windows network
# The comment is a description of the shared folder
# Can visit/srv/qfxFtp/HDD_sdb1/qfxSamba_share/table of Contents
# Can write
# Specify a valid user
[ Qfx Share Dir]
comment = Qfx share Folder
path =/srv/qfxFtp/HDD_sdb1/qfxSamba_share
writable = yes 
valid users = qfxsamba

4. Restart service#

systemctl restart smbd

5. Windows access samba#

Suppose the IP address of my Linux is 10.12.55.69

Enter in the Windows file browser:

\\10.12.55.69

Then the login dialog box will pop up, enter the user name and password to log in (the password is the one set by smbpasswd -a qfxsamba)

Possible problems

Samba only supports NTLM authentication, while WIN7 or VISTA uses NTLMv2 authentication, so some settings are required. The specific settings are as follows:

Start-> 
run-> 
secpol.msc->
Local strategy->
Security Options->
Network security: LAN manager authentication level->
Send LM and NTLMv2,If negotiated, use NTLMv2(Session security&)->
Finish setting

6. Add multiple users or groups#

Now the only user who can log in to the samba server is qfxsamba.

The following methods have not been tested:

If multiple accounts are more suitable for accessing the shared folder, please change the effective user as shown below in the /etc/samba/smb.conf file.

valid users = user1, user2, user3

You can also use smbpasswd to set a Samba password for each user.

smbpasswd -a user1  #[Enter the password to access Samba,Not user1 user password]
# Set up
smbpasswd -a user2  #[Enter the password to access Samba,Not user2 user password]
# Set up
smbpasswd -a user3  #[Enter the password to access Samba,Not user3 user password]
# Set up

To allow a group of users to access the shared folder, use the following configuration in /etc/samba/smb.conf.

valid users = @sambashare

Create group

groupadd sambashare

Then add the user to this group

gpasswd -a qfxsamba  sambashare
gpasswd -a user1     sambashare
gpasswd -a user2     sambashare
gpasswd -a user3     sambashare

This group needs to have write access to the shared folder, which can be achieved through the following two commands.

Set sambashare as the group owner of the shared folder:

chgrp sambashare /path/to/shared/folder -R

Write permissions granted to the group:

chmod g+w /path/to/shared/folder/-R

OK!
Above, Enjoy~

Recommended Posts

[Linux] Build Samba server (ubuntu16.04)
ubuntu 16.04 build pptpd V** server
Build Ubuntu 12.04 cross compilation server
Ubuntu16.04 build GitLab server tutorial
Linux (ubuntu 12.04)
Build Nginx-RTMP live server on ubuntu
Ubuntu16.04 build php5.6 Web server environment
Build a file server on ubuntu
[Linux] Pure ubuntu quickly build pagoda panel
How to use Samba server on Ubuntu 16.04
Ubuntu build etcd
Ubuntu build Seafile
Build a Minecraft Bedrock Edition server (Ubuntu)
Linux (centos7) build gitlab
Ubuntu 18.04 LTS LAMP build
Ubuntu Linux study notes
ubuntu install nginx server
Embedded Linux development environment to build and configure Ubuntu
Deploy FTP server under ubuntu
Build OpenV** Server under CentOS7
Windows 10 install Linux subsystem Ubuntu
ubuntu16.04 build vim and pyt
Install OpenSSL 1.0.2 on Ubuntu Server 14.04
Ubuntu Server Chapter 8 DNS Service
Build OpenLDAP server under CentOS7
Ubuntu Server Chapter 3 Package Management
2.5 Linux (Ubuntu18.04) install database PostgreSQL
Configure tomcat on ubuntu server
Ubuntu Server Chapter 7 Remote Management
Server upgrade Ubuntu 20.04 LTS record
Teach you how to build a Git server on Ubuntu
How to build an NFS file sharing server on Ubuntu 16.04
ubuntu1804 build the latest Suricata
Server upgrade Ubuntu 20.04 LTS record
Ubuntu server builds Java web server
ubuntu build python development environment
Ubuntu deploys squid proxy server
Initial setup of Ubuntu 16.04 server
Build an Ubuntu Linux development environment on a Vmware virtual machine
Ubuntu 18.04.1 build Java environment and HelloWorld
Detailed ubuntu14.04 build (migration) hustoj record
Virtual machine Linux Ubuntu installation tutorial
CentOS8.1 build Gitlab server detailed tutorial
Install Chef server workstation on Ubuntu 18.04
MySQL connected to remote Ubuntu server
[Linux] Some high-efficiency tools of Ubuntu
UBUNTU 16.04 LTS experience (commemorating LINUX-25 anniversary)
Ubuntu Linux CPU GPU performance test
Build an FTP server under centos7
Practical Ubuntu shortcut keys for linux
Build Nginx environment on Linux (CentOS)
Install Ubuntu 18.04 server with kvm virtualization
(centos7) linux build nginx load balancing build
Centos7 build java web server tomcat
Ubuntu Server Chapter 2 Command Line Basics
Linux basics (root privileges in Ubuntu)
Build Discuz forum based on ubuntu
Use Ubuntu 16.04 for initial server setup
Install Oracle 11gR2 on Ubuntu Server 12.4.0
Linux basics (Ubuntu copy and paste)