smb服務配置詳解
阿新 • • 發佈:2018-08-06
roo set 準備 inf disabled centos cif client 添加 配置用戶共享用戶
環境說明
服務端IP | 客戶端IP |
---|---|
192.168.24.248 | 192.168.24.145 |
在服務端操作如下
1.環境準備
關閉防火墻和selinux
[root@linfan ~]systemctl disable firewalld
[root@linfan ~]systemctl stop firewalld
[root@linfan ~]sed -ri ‘#^SELINUX=#cSELINUX=Disabled‘ /etc/selinux/config
[root@linfan ~]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
在全局變量中添加如下內容:
[root@linfan ~]# 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
[root@linfan ~]# mkdir -p /opt/lin/
[root@linfan ~]# chown -R lin.lin /opt/lin/
5.配置共享
[root@linfan ~]# 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 [root@linfan ~]# 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服務
[root@linfan ~]# systemctl start smb
重啟smb服務
[root@linfan ~]# systemctl restart smb
重新加載smb服務
[root@linfan ~]# systemctl reload smb
設置smb開機自啟動
[root@linfan ~]# systemctl enable smb
在客戶端操作
1.查看smb服務器共享了哪些資源
[root@linfan ~]# smbclient -L 192.168.24.248 -U share
2.創建掛載目錄
[root@linfan ~]# mkdir -p /opt/smb/
3.將smb服務器上的lin掛載到本地
[root@linfan ~]# mount -t cifs //192.168.24.248/lin /opt/smb -o username=share,password=1
[root@linfan ~]# 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.進入客戶端共享目錄創建新文件
[root@linfan opt]# cd /opt/smb
[root@linfan smb]# mkdir l
[root@linfan smb]# touch k
[root@linfan smb]# ls
k l
5.在服務端驗證
[root@linfan ~]# cd /opt/lin
[root@linfan lin]# ls
k l
匿名用戶共享
環境說明
服務端IP | 客戶端IP |
---|---|
192.168.24.248 | 192.168.24.146 |
在服務端操作如下
1.環境準備
關閉防火墻和selinux
[root@linfan ~]systemctl disable firewalld
[root@linfan ~]systemctl stop firewalld
[root@linfan ~]sed -ri ‘#^SELINUX=#cSELINUX=Disabled‘ /etc/selinux/config
[root@linfan ~]setenforce 0
2.安裝smb服務
[root@linfan ~]# yum -y install samba-*
3.編輯配置文件
[root@linfan ~]# 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. 創建共享目錄
[root@linfan ~]# mkdir /opt/doudou
[root@linfan ~]# chmod 777 /opt/doudou
[root@linfan ~]# 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.編輯共享文件
[root@linfan ~]# cat >> /etc/samba/smb.conf <<EOF
> [doudou]
> comment = doudou
> path = /opt/doudou
> browseable = yes
> guest ok = yes
> writable = yes
> public = yes
> EOF
[root@linfan ~]# tail -7 /etc/samba/smb.conf
[doudou]
comment = doudou
path = /opt/doudou
browseable = yes
guest ok = yes
writable = yes
public = yes
6.啟動smb服務
[root@linfan ~]# systemctl start smb
7.在客戶端查看smb服務共享 無需輸入密碼 直接回車即可
[root@linfan ~]# smbclient -L 192.168.24.248 -U‘Bad User‘
8.創建掛載目錄
[root@linfan ~]# mkdir -p /opt/smb
9.將smb服務器的共享文件doudou 掛載到本地客戶端
[root@linfan ~]# mount -t cifs //192.168.24.248/doudou /opt/smb -o username=‘Bad User‘
[root@linfan ~]# df -h
10.切換到新的共享目錄創建文件
[root@linfan ~]# cd /opt/smb
[root@linfan smb]# mkdir lin
[root@linfan smb]# touch wu
[root@linfan smb]# ls
lin wu
11.在服務端驗證
[root@linfan doudou]# ls
lin wu
smb服務配置詳解