ready:
①Two Centos7.6
192.168.1.67 | client side |
192.168.1.88 | server side |
②Stop the firewall and selinux, turn off the firewall and start on by default
systemctl stop firewalld
systemctl disable firewalld
# 查看selinux运行状态
getenforce
# 修改selinux状态
vim /etc/selinux/config
1. Install samba on the server and samba-client on the client
yum install samba samba-client -y
systemctl start smb nmb
# 查看samba运行状态
netstat -antp
2. Create a new linux user without login permission, add it as a samba user and set a password
# 创建一个不能登录的linux用户
useradd -s /sbin/nologin wenlong
# 将linux系统用户设为samba用户,并按照提示设置密码
pdbedit -a wenlong
# //读取当前samba用户列表
pdbedit -L
Three, view samba shared files, the default is wenlong's home directory
# 在客户端192.168.1.67查看wenlong用户的共享信息,默认是wenlong的家目录
smbclient -U wenlong -L //192.168.1.88
# 在客户端client登录查看共享文件
smbclient -U wenlong //192.168.1.88/wenlong
Four, custom shared space, test
①Edit the samba configuration file smb.conf on the server side, add the sambatest block code below, and the node name sambatest
vim /etc/samba/smb.conf
[sambatest]
# 共享目录是根目录下的test文件夹
path = /test
public = yes
# 是否可见
browseable = yes
guest ok = yes
writable = yes
②Create the shared directory marked by path in the configuration file on the server side, and grant permissions
# 创建共享测试文件夹test
mkdir /test
# 修改权限,777给所有用户提供读写执行权。1粘着位,表示仅允许删除或重命名自己的文件
# 这里涉及到SUID、SGID、SBIT,代表文件包括/etc/passwd,/usr/bin/locate,和下边这种情况
# SUID用4表示,SGID用2表示,SBIT用1表示
# 备注:大多数情况不需要修改,除非特殊情况
chmod 1777 /test/
③Restart the samba service on the server side and test whether the configuration file modification is correct
# 修改配置文件后,重启smb服务
systemctl restart smb nmb
# 查看配置文件是否正确
testparm
④ The client client looks at the shared folder and sees the shared folder named sambatest
# 再次查看wenlong共享的文件
smbclient -U wenlong -L //192.168.1.88
⑤The client client logs in to the shared node sambatest, and can perform samba's own operations
# 在client端使用wenlong从共享文件节点sambatest登录
smbclient -U wenlong //192.168.1.88/sambatest
Five, mount the share to the local directory
①Create a new mount point clienttest on the client side, and create clienttest in the root directory
# 创建挂载点
mkdir /clienttest
②Create a temporary mount and view the mount situation
# 临时挂载
mount -t cifs -o username=wenlong,password=123456 //192.168.1.88/sambatest /clienttest
# 查看挂载情况
df -h
③ Permanently mount, edit the fstab file on the client side, restart the server to view the mount
vim /etc/fstab
//192.168.1.88/sambatest /clienttest cifs defaults,username=wenlong,password=123456 0 0
df -h
④Check the shared folder mounted on the client side and create a new test file
# 进入挂载点
cd /clienttest/
# 新建测试文件aaa
vim aaa
# 查看当前文件列表
ll
# 查看aaa文件内容
cat aaa
⑤View the test file on the server server
cd /test/
ll
cat aaa