服务端 wangxiaolan 172.16.30.11
客户端 chenwanli 172.16.30.111
//使用yum命令安装samba服务器:
[root@wangxiaolan ~]# yum -y install samba-*
//在全局配置中添加如下内容:
[root@wangxiaolan ~]# vim /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 //添加此行内容
//创建一个共享目录cwl
[root@wangxiaolan ~]# mkdir /opt/cwl
[root@wangxiaolan ~]# chmod 777 /opt/cwl/
[root@wangxiaolan ~]# ll /opt/
total 0
drwxrwxrwx. 3 root root 26 Aug 4 15:17 cwl
//配置共享
[root@wangxiaolan ~]# cat >> /etc/samba/smb.conf <<EOF
> [cwl]
> comment = cwl
> path = /opt/cwl
> browseable = yes
> guest ok = yes
> writable = yes
> public = yes
> EOF
[root@wangxiaolan ~]# tail -8 /etc/samba/smb.conf
[cwl]
comment = cwl
path = /opt/cwl
browseable = yes
guest ok = yes
writable = yes
public = yes
//启动smb服务:
[root@wangxiaolan ~]# systemctl start smb
[root@wangxiaolan ~]# smbclient -L 172.16.30.11 -U 'Bad User'
Enter Bad User's password:
Anonymous login successful
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
//在客户机查看samba服务器有哪些共享资源
[root@chenwanli ~]# smbclient -L 172.16.12.128 -U 'Bad User'
Sharename Type Comment
--------- ---- -------
chen Disk chen
IPC$ IPC IPC Service (Samba Server Version 4.1.1)
Anonymous login successful
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
Server Comment
--------- -------
Workgroup Master
--------- -------
//将samba服务器的共享资源wangqing挂载到客户机本地
[root@chenwanli ~]# mount -t cifs //172.16.30.11/cwl /opt/smb/ -o username='Bad User'
[root@chenwanli ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/rhel-root 18G 3.1G 15G 18% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 914M 140K 914M 1% /dev/shm
tmpfs 914M 8.9M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
//172.16.16.30/cwl 18G 3.1G 15G 18% /opt/smb
//在客户机上进入共享目录创建新文件
[root@chenwanli smb]# ls
[root@chenwanli smb]# touch slm
[root@chenwanli smb]# mkdir aaaa
[root@chenwanli smb]# ls
slm aaaa
/到服务器上验证
[root@wangxiaolan ~]# cd /opt/cwl/
[root@wangxiaolan cwl]# ls
slm aaaa