Linux安装配置samba

yum update
yum install -y samba samba-client samba-common cifs-utils

smb.conf的配置例子如下

 #cat  /etc/samba/smb.conf
 [global]
 workgroup = WORKGROUP
 server string = x200
 dns proxy = no
# interfaces = eth0
 syslog = 0
 browsable = yes
 map to guest = bad user
 nt pipe support = no
 encrypt passwords = true
 passdb backend = tdbsam
 obey pam restrictions = yes
 unix password sync = no
 netbios name = MY_SHARE_SERVER

#== Share Definitions ===
[share]  
path = /opt/share_folder
valid users=share_user
directory mask = 0755
create mask = 0664
writable = yes
guest ok = no
read only = no
public = no

配置好smb.conf后需要创建目录和设置用户密码

useradd share_user #创建Linux用户
mkdir /opt/share_folder #创建目录
chown -R share_user:share_user  /opt/share_folder #设置文件夹归属权限
chmod 755 /opt/share_folder    #设置文件夹读写权限
smbpasswd -a share_user #设置密码

最后启动smb后测试。

Linux挂载Samba

默认情况直接个mount -t cifs进行挂载,如使用mount.cifs的需要先安装cifs-utils

yum install cifs-utils -y
mount -t cifs -o username="Username",password="Password" //IP/share /mnt/
umount /mnt/

使用mount.cifs挂载

mount.cifs -o username="Username",password="Password" //IP/share /mnt/
umount.cifs /mnt/

加入fstab开机自动挂载需要将账号密码等参数写入一个文件

#cat /opt/pass.txt
username=YOURusername
password=YOURpassword  

然后写入fstab的格式大致如下的最后一行

cat /etc/fstab
/dev/sda1/                       ext4    defaults        1 1
/dev/sda2               swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
//IP/share    /mnt        cifs    credenials=/opt/pass.txt    0 0

  匿名登陆也是需要带username参数的,否则会报错。