Samba is a service to share files with others. That support UTF-8 code, so, We can share files with Chinese names.
Install
We always use samba in lan, with others, so, that service don’t need to be a HA Service.
There are two method to install samba: one is yum, the other is compile. Because that service don’t need to be an HA Service, we can use yum to install it.
yum install samba
Let me see the directory tree with Samba:
[root@localhost samba]# tree
.
├── lmhosts
├── smb.conf
└── smb.conf.example
0 directories, 3 files
We can see, There have a smb.conf
, That is samba’s configuration file,and there have that file’s example.
Config Samba
Edit smb.conf:
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
Do not edit the original file.
There are some important key:
- security: That is the method to login samba. We can use share and user.
Create a share directory
Write a model in smb.conf. Like
[test]
comment=
path = /test
public = no
browseable = yes
valid user = test1,test
write list = test1
create mask = 0644
directory mask = 0755
Comment key: Information of this model.
path: Directory path
public: This directory is a public directory ?
browseable: Dose that directory can browse able by each user.
valid user: Users allowed to access
write list: Users allowed to wirte
mask: Set upload files mask
OK,There is a samba’s rule.
I will add two user named test and test1,and i will add that user to smbdb.
useradd test -s /sbin/nologin
useradd test1 -s /sbon/nologin
smbpasswd -a test
smbpasswd -a test1
Then ,restart samba service.
Verification
Install a tool named samba-client,and input command:
bash# smbclient -L \\192.168.89.164 -U test
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
test Disk
IPC$ IPC IPC Service (Samba 4.9.1)
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
--------- -------
If command line return this information ,It means that the configuration is successful.
To use
Mount to windows:
Input url \\192.168.89.164
in This PC’s url box. The system requires me to enter user and password.
At first time ,I’m going to use test.
Copy a file to that directory, and the OS tells us that it cannot be written in that directory with insufficient permissions.
Then going to use test1 ,and try again.
We found that read and write are normal in this time.
Virtual user
Samba’s virtual user like user’s alias.
Create a samba user list file:
test1 = t1 t2 t3
Add a key to smb.conf
[global]
security = user
username map = /etc/samba/smbusers
Restart samba and login try again.
This time ,we use user t1 and the password same as test1.
If you login ,that mean is your virtual account is configured correctly.
Observe the samba’s file, we can find ,that this file is the same as file for test1’s.
So, I always call that is samba user’s alias.
That’s all.
Thanks.
Reference: