Linux Samba安装, 配置与使用

date: 2013.05.23; modification:2017.12.06

目录:

1 安装

sudo apt-get install samba samba-common

2 Samba配置

sudo vi /etc/samba/smb.conf

[lunch]
    comment = Samba lunch
    browseable = no
    path = /media/d/other/lunch
    public = no
    guest ok = no
    writeable = no

3 启动

对于CentOS 6.5, 默认服务未启动, 可以用chkconfig命令查看.

启动samba服务:

sudo service smb start

如果CentOS 6.5默认启动了selinux, 则客户端访问可能会报错: 权限不够. 这是因为selinux导致其他机器访问linux的文件系统时被拒绝, 简单暴力的解决办法如下:

setenforce 0 回车即可.

4 smb用户配置

如果配置与连接命令都对, 但是报错:

mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

则需要添加samba用户.

添加samba用户:

sudo smbpasswd -a user1

注: user1需要是samba服务器上的已有用户.

5 权限配置

[lunch]
    comment = Samba lunch
    browseable = no
    path = /media/d/other/lunch
    public = no
    guest ok = yes
    writeable = yes
    valid user = user1

这样user1可以写, 但是guest不能写.

6 Linux访问Windows共享

sudo mount -t cifs -o username=uuu,password=ppp //192.168.1.100/sambapath ./smb

sudo mount -t smbfs //172.16.1.123/test ./mnt/

7 FAQ

1. 挂载时报错: wrong fs type

log:

mount: wrong fs type, bad option, bad superblock on //172.16.5.82/photo_share,
       missing codepage or helper program, or other error
       (for several filesystems (e.g. nfs, cifs) you might
       need a /sbin/mount.<type> helper program)
       系统日志中可能有一些重要的信息,
       试试用 dmesg | tail 之类的命令查看.

解决:

sudo apt-get install smbfs