server
安装 samba
[[email protected] ~]# yum -y install samba
新建共享
[[email protected] ~]# vim /etc/samba/smb.conf
workgroup = WORKGROUP
hosts allow = 127. 192.168.3.
[public] ##共享名
comment = Public Stuff ##说明
path = /smbpub ##路径
public = no ##公开,可匿名访问
writable = yes ##是否可写
printable = no ##是否是打印机,如果共享目录必须为no
write list = smbrw ##可写名单
read list = smbro ##只读名单
browseable = yes ##可浏览
创建共享目录,设置权限
[[email protected] ~]# mkdir /smbpub
[[email protected] ~]# chmod 777 /smbpub
[[email protected] ~]# semanage fcontext -a -t samba_share_t '/smbpub(/.*)?'
[[email protected] ~]# restorecon -Rv /smbpub/
创建 samba 用户
samba 用户必须在系统中存在,通过 pdbedit 和 smbclient 均可创建 samba 用户
[[email protected] ~]# useradd -s /sbin/nologin smbrw
[[email protected] ~]# useradd -s /sbin/nologin smbro
[[email protected] ~]# (echo redhat;echo redhat) | pdbedit -a smbrw
[[email protected] ~]# (echo redhat;echo redhat) | smbpasswd -a smbro
[[email protected] ~]# systemctl restart smb nmb
[[email protected] ~]# systemctl enable smb nmb
开放防火墙
[[email protected] ~]# firewall-cmd --add-service=samba --add-service=samba-client
[[email protected] ~]# firewall-cmd --add-service=samba --add-service=samba-client --permanent
desktop
临时挂载
[[email protected] ~]# yum -y install cifs-utils samba-client
[[email protected] ~]# mkdir /mnt/smbmount
[[email protected] ~]# mount -t cifs -o username=smbrw,password=redhat //192.168.3.11/public /mnt/smbmount
多用户挂载,开机自动挂载
用只读用户挂载,不同的用户可以更新不同凭证
/etc/fstab所有用户可读,将 samba 用户和密码保存到 root 家目录可提高安全性
[[email protected] ~]# vim /etc/fstab
//192.168.3.11/public /mnt/smbpmnt cifs credentials=/root/smbpass,multiuser,sec=ntlmssp 0 0
[[email protected] ~]# echo "username=smbro" >> /root/smbpass
[[email protected] ~]# echo "password=redhat" >> /root/smbpass
[[email protected] ~]# mkdir /mnt/smbpub
[[email protected] ~]# mount -a
[[email protected] ~]# cifscreds add -u smbrw 192.168.3.11 ##更新用户凭证
autofs 挂载
[[email protected] ~]# yum -y install autofs
[[email protected] ~]# vim /etc/auto.master
/netshare(挂载目录上级目录) /etc/netauto(映射文件)
[[email protected] ~]# vim /etc/netauto
smbmount -fstype=cifs,username=smbro,password=redhat ://192.168.3.11/public
samba-client 上传下载
[[email protected] ~]# yum -y install samba-client
[[email protected] ~]# smbclient //172.25.0.11/public -U smbro%redhat
smb: \> lcd /etc
smb: \> put passwd
NT_STATUS_ACCESS_DENIED opening remote file \passwd
[[email protected] ~]# smbclient //172.25.0.11/public -U smbrw%redhat
smb: \> lcd /etc
smb: \> put passwd
putting file passwd as \passwd (2091.6 kb/s) (average 2091.8 kb/s)