主機名 | IP |
---|---|
服務器 | 192.168.100.100 |
客戶端 | 192.168.100.129 |
第一步配置SAMBA
服務端配置
新建samba用戶
[root@localhost ~]# useradd jerry -s /sbin/nologin
[root@localhost ~]# smbpasswd -a jerry
新建共享目錄,賦予權限
[root@localhost ~]# mkdir /date/samba/share -p
[root@localhost ~]# chown jerry.jerry /date/samba/share -R
修改配置文件,在/etc/samba/smb.conf的配置文件最下面添加
[root@localhost ~]# cat /etc/samba/smb.conf
[samba-share]
comment = This is share
path = /date/samba/share
public = no
writable = yes
```
**映射系統用戶,並將路徑寫入smb.conf配置中**
[root@localhost ~]# echo “jerry = qinyong” > /etc/samba/smbusers //將系統用戶jerry映射爲qinyong虛擬用戶
[root@localhost ~]# cat //etc/samba/smb.conf
[global]
workgroup = SAMBA
security = user
map to guest = Bad User
username map = /etc/samba/smbusers
passdb backend = tdbsam
“`
重啓服務
[root@localhost ~]# systemctl restart smb.service
客戶端驗證,查看共享目錄
[root@localhost ~]# smbclient -L 192.168.100.100 -U qinyong //需要輸入密碼
Enter SAMBA\qinyong's password:
Sharename Type Comment
--------- ---- -------
samba-shard Disk This is shard
samba-share Disk This is share
IPC$ IPC IPC Service (Samba 4.7.1)
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
-----
掛載
[root@localhost ~]# mkdir /samba -p
[root@localhost ~]# mount -t cifs -o user=qinyong,pass=111 //192.168.100.100/samba-share /samba/
檢測
[root@localhost ~]# echo "hehe" >> 123 //客戶端創建
[root@localhost ~]# ls
123
[root@localhost ~]# cat /date/samba/share/123 //服務驗證該用戶有讀寫權限
自動掛載
[root@localhost ~]# vim /etc/fstab
//192.168.100.100/samba-share /samba cifs defaults,_netdev,user=qinyong,pass=111 0 0
檢測
[root@samba-client ~]# mount -a
[root@samba-client ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 865676 155344 753453 22% /
devtmpfs 490012 0 494352 0% /dev
tmpfs 499860 0 4435340 0% /dev/shm
tmpfs 499860 6880 4354350 2% /run
tmpfs 499860 0 493440 0% /sys/fs/cgroup
/dev/sda1 1134546 135675 83434 12% /boot
tmpfs 99972 0 14356 12% /run/user/0
//192.168.100.100/samba-shard 1832345 3215464 1326434 37% /cifs
//192.168.100.100/samba-share 1832345 3215464 1326434 37% /samba //掛載成功