ubuntu samba服务搭建

ubuntu 16.04 64bit samba服务搭建。

一、ubuntun 系统

1、samba的安装:

1
2
sudo apt-get install samba 
sudo apt-get install smbclient (客户端,可选)

注:如果安装有错误,则要更新源:

1
sudo apt-get update

2、创建共享目录(可选):

1
2
mkdir /home/latelee/share 
sudo chmod 777 /home/latelee/share

注:可指定共享目录,不过一般建议使用个人home目录,本文为/home/latelee

3、创建Samba配置文件:

3.1. 保存现有的配置文件(可选)

1
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

3.2. 修改现配置文件

1
sudo vim /etc/samba/smb.conf

在smb.conf最后添加

1
2
3
4
5
6
[home] # 用于显示在windows的名称
    comment = samba home # 注释,不要也可以
    path = /home/latelee # 共享目录路径
    writable = yes # 可写
    browseable = yes # 可看
    guest ok = no # 不允许guest

注:格式如上,路径根据实际情况改。注意,配置文件中不要使用中文注释。

4、创建samba帐户

1
2
3
4
5
  sudo touch /etc/samba/smbpasswd (此步不要也行)
  sudo smbpasswd -a latelee(用户名)

New SMB password:(此处密码,建议与登陆密码相同)
Retype new SMB password:(此处密码,建议与登陆密码相同)

注:如果没有第四步,登录时会提示 session setup failed: NT_STATUS_LOGON_FAILURE

5、重启samba服务器

1
2
3
4
5
6
fc10系统: 
/etc/init.d/smb restart

ubuntu系统:
sudo /etc/init.d/samba restart
sudo /etc/init.d/smbd restart (此步可不要)

注:不同版本路径、名称可能不同,根据实际情况尝试。

6、测试 (不要也行)

1
smbclient -L //localhost/共享目录 

7、使用windows连接

在windows地址栏中输入:\\<虚拟机IP地址>\home,如:\\192.168.28.131\home,然后输入账号密码即可。

二、CentOS 系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
rpm -qa|grep samba
sudo yum install -y samba


[homes]
comment = Home Directories
valid users = lijj
path = /home/lijj
browseable = Yes
writable = yes
inherit acls = Yes

sudo smbpasswd -a latelee

sudo firewall-cmd --add-service=samba --permanent
sudo firewall-cmd --reload
sudo systemctl restart smb

如提示无权限,关闭selinux:

1
2
3
4
5
6
临时生效:
setenforce 0
改配置:
vim /etc/sysconfig/selinux
#SELINUX=enforcing
SELINUX=disabled