配置用户共享用户
环境说明
服务端IP | 客户端IP |
---|---|
192.168.24.248 | 192.168.24.145 |
在服务端操作如下
1.环境准备
关闭防火墙和selinux
[[email protected] ~]systemctl disable firewalld
[[email protected] ~]systemctl stop firewalld
[[email protected] ~]sed -ri ‘#^SELINUX=#cSELINUX=Disabled‘ /etc/selinux/config
[[email protected] ~]setenforce 0
2.安装samba服务器:
yum -y install samba-*
3.共享用户配置
useradd -M lin
为用户lin创建smb共享密码
smbpasswd -a lin
将lin用户映射为share用户:
echo ‘lin = share‘ > /etc/samba/smbusers
在全局变量中添加如下内容:
[[email protected] ~]# vi /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run ‘testparm‘ to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA
security = user
username = /etc/samba/smbusers //在此添加
4. 创建一个共享目录lin
[[email protected] ~]# mkdir -p /opt/lin/
[[email protected] ~]# chown -R lin.lin /opt/lin/
5.配置共享
[[email protected] ~]# cat >> /etc/samba/smb.conf <<EOF
> [lin]
> comment = lin
> path = /opt/lin
> browseable = yes
> guest ok = yes
> writable = yes
> write list = share
> public = yes
> EOF
[[email protected] ~]# tail -8 /etc/samba/smb.conf
[lin]
comment = lin
path = /opt/lin
browseable = yes
guest ok = yes
writable = yes
write list = share
public = yes
6.smb服务配置
启动smb服务
[[email protected] ~]# systemctl start smb
重启smb服务
[[email protected] ~]# systemctl restart smb
重新加载smb服务
[[email protected] ~]# systemctl reload smb
设置smb开机自启动
[[email protected] ~]# systemctl enable smb
在客户端操作
1.查看smb服务器共享了哪些资源
[[email protected] ~]# smbclient -L 192.168.24.248 -U share
2.创建挂载目录
[[email protected] ~]# mkdir -p /opt/smb/
3.将smb服务器上的lin挂载到本地
[[email protected] ~]# mount -t cifs //192.168.24.248/lin /opt/smb -o username=share,password=1
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 6.0G 12G 35% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.9M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 125M 890M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt
//192.168.24.248/lin 17G 6.0G 12G 36% /opt/smb
4.进入客户端共享目录创建新文件
[[email protected] opt]# cd /opt/smb
[[email protected] smb]# mkdir l
[[email protected] smb]# touch k
[[email protected] smb]# ls
k l
5.在服务端验证
[[email protected] ~]# cd /opt/lin
[[email protected] lin]# ls
k l
匿名用户共享
环境说明
服务端IP | 客户端IP |
---|---|
192.168.24.248 | 192.168.24.146 |
在服务端操作如下
1.环境准备
关闭防火墙和selinux
[[email protected] ~]systemctl disable firewalld
[[email protected] ~]systemctl stop firewalld
[[email protected] ~]sed -ri ‘#^SELINUX=#cSELINUX=Disabled‘ /etc/selinux/config
[[email protected] ~]setenforce 0
2.安装smb服务
[[email protected] ~]# yum -y install samba-*
3.编辑配置文件
[[email protected] ~]# vi /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run ‘testparm‘ to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA
security = user
map to guest = Bad User //在此添加
4. 创建共享目录
[[email protected] ~]# mkdir /opt/doudou
[[email protected] ~]# chmod 777 /opt/doudou
[[email protected] ~]# ll /opt/
total 0
drwxrwxrwx. 2 root root 6 Aug 6 19:08 doudou
drwxr-xr-x. 8 root root 220 Jul 18 17:09 lin.d
5.编辑共享文件
[[email protected] ~]# cat >> /etc/samba/smb.conf <<EOF
> [doudou]
> comment = doudou
> path = /opt/doudou
> browseable = yes
> guest ok = yes
> writable = yes
> public = yes
> EOF
[[email protected] ~]# tail -7 /etc/samba/smb.conf
[doudou]
comment = doudou
path = /opt/doudou
browseable = yes
guest ok = yes
writable = yes
public = yes
6.启动smb服务
[[email protected] ~]# systemctl start smb
7.在客户端查看smb服务共享 无需输入密码 直接回车即可
[[email protected] ~]# smbclient -L 192.168.24.248 -U‘Bad User‘
8.创建挂载目录
[[email protected] ~]# mkdir -p /opt/smb
9.将smb服务器的共享文件doudou 挂载到本地客户端
[[email protected] ~]# mount -t cifs //192.168.24.248/doudou /opt/smb -o username=‘Bad User‘
[[email protected] ~]# df -h
10.切换到新的共享目录创建文件
[[email protected] ~]# cd /opt/smb
[[email protected] smb]# mkdir lin
[[email protected] smb]# touch wu
[[email protected] smb]# ls
lin wu
11.在服务端验证
[[email protected] doudou]# ls
lin wu
原文地址:http://blog.51cto.com/13858192/2155437
时间: 2024-10-12 08:47:02