samba共享

server

安装 samba

[root@server ~]# yum -y install samba

新建共享

[root@server ~]# 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  ##可浏览

创建共享目录,设置权限

[root@server ~]# mkdir /smbpub
[root@server ~]# chmod 777 /smbpub
[root@server ~]# semanage fcontext -a -t samba_share_t '/smbpub(/.*)?'
[root@server ~]# restorecon -Rv /smbpub/

创建 samba 用户

samba 用户必须在系统中存在,通过 pdbedit 和 smbclient 均可创建 samba 用户

[root@server ~]# useradd -s /sbin/nologin smbrw
[root@server ~]# useradd -s /sbin/nologin smbro
[root@server ~]# (echo redhat;echo redhat) | pdbedit -a smbrw
[root@server ~]# (echo redhat;echo redhat) | smbpasswd -a smbro
[root@server ~]# systemctl restart smb nmb
[root@server ~]# systemctl enable smb nmb

开放防火墙

[root@server ~]# firewall-cmd --add-service=samba --add-service=samba-client
[root@server ~]# firewall-cmd --add-service=samba --add-service=samba-client --permanent

desktop

临时挂载

[root@desktop ~]# yum -y install cifs-utils samba-client
[root@desktop ~]# mkdir /mnt/smbmount
[root@desktop ~]# mount -t cifs -o username=smbrw,password=redhat //192.168.3.11/public /mnt/smbmount

多用户挂载,开机自动挂载

用只读用户挂载,不同的用户可以更新不同凭证

/etc/fstab所有用户可读,将 samba 用户和密码保存到 root 家目录可提高安全性

[root@desktop ~]# vim /etc/fstab
//192.168.3.11/public /mnt/smbpmnt cifs credentials=/root/smbpass,multiuser,sec=ntlmssp 0 0
[root@desktop ~]# echo "username=smbro"  >> /root/smbpass
[root@desktop ~]# echo "password=redhat"  >> /root/smbpass
[root@desktop ~]# mkdir /mnt/smbpub
[root@desktop ~]# mount -a

[user@desktop ~]# cifscreds add -u smbrw 192.168.3.11  ##更新用户凭证

autofs 挂载

[root@desktop ~]# yum -y install autofs
[root@desktop ~]# vim /etc/auto.master
/netshare(挂载目录上级目录) /etc/netauto(映射文件)
[root@desktop ~]# vim /etc/netauto
smbmount -fstype=cifs,username=smbro,password=redhat ://192.168.3.11/public

samba-client 上传下载

[root@desktop ~]# yum -y install samba-client
[root@desktop ~]# smbclient //172.25.0.11/public -U smbro%redhat
smb: \> lcd /etc
smb: \> put passwd
NT_STATUS_ACCESS_DENIED opening remote file \passwd

[root@desktop ~]# 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)

添加新评论