安装samba

安装samba

参考链接

  • 参考链接: https://www.cnblogs.com/webnote/p/5741793.html

安装sambat客户端

yum -y install samba samba-client

配置samba环境

配置一个新目录

  • 备份原配置文件
  • 新建配置文件
  • 测试配置是否成功
# 备份原配置文件
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

# 并添加一个新的配置
vim /etc/samba/smb.conf

# 测试是否成功
testparm
testparm -s smb.conf

配置文件示例

# 添加一个root目录
# 工作组
[global]
workgroup = WORKGROUP
# 设置samba服务器安全级别, user:samba服务器验证, share:无权限验证; server:第三方主机验证;domain
security = user
netbios name = MYSERVER
# 设置samba服务器名称
server string = Samba Server Version %v
passdb backend = tdbsam
#printing = cups
#printcap name = cups
load printers = yes
cups options = raw

# 共享目录的名字
[root]
comment = Root Directories
path = /
valid users = root
public = yes
writable = yes
browseable = yes
create mask = 0644
directory mask = 0755

# 共享目录的名字
[homes]
comment = Home Directories
path = /home
read only = No

添加samba用户

# 增加用户, 并设置密码c0
smbpasswd -a root

其他命令

  • smbpasswd -a root, 增加用户, 并设置密码c0
  • smbpasswd -d 冻结用户
  • smbpasswd -e 恢复用户,解冻用户
  • smbpasswd -n 把用户的密码设置成空, 需要[global]添加, null passwords = yes

防火墙配置

# centos6.x
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 137 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 138 -j ACCEPT
# centos7.x, 成功会显示success
firewall-cmd --permanent --add-port=139/tcp
firewall-cmd --permanent --add-port=445/tcp
systemctl restart firewalld

设置Samba服务开机自启动

# centos6.x
service smb restart
service nmb restart

# centos7.x
systemctl restart smb
systemctl enable smb

# 设置开机启动
chkconfig --list | grep smb
chkconfig --level 35 smb on
chkconfig --level 35 nmb on

查看当前smb的状态

  • 列出smb服务共享目录

    • smbclient -L 10.8.204.189,
    • smbclient -L localhost, 密码为samba用户的密码
  • 连接测试

    • smbclient //10.8.204.189/homes, homes是配置的目录名称
    • smbclient //192.168.18.99/public -U zxw, 使用指定用户名
  • 查看分享, 在连接之后

    • smb: > dir
    • smb: > ls
    • 无法查看时,关掉se
      • setenforce 0
      • getenforce, 查看状态应该为: Permissive
  • 本地可以访问,但是其他机器无法访问时,可能是端口被禁了

    • 确认是否端口不可访问, 使用nginx监听再访问
      • curl -voa http://10.8.204.189:8888/index.html -H "HOST:a.aa.com", 8888可访问
      • curl -voa http://10.8.204.189:139/index.html -H "HOST:a.aa.com", 139不可访问

开启时的日志文件

[root@localhost samba]# smbclient -L localhost
Enter WORKGROUP\root's password: 

    Sharename       Type      Comment
    ---------       ----      -------
    root            Disk      Root Directories
    print$          Disk      Printer Drivers
    IPC$            IPC       IPC Service (Samba Server Version 4.7.1)
Reconnecting with SMB1 for workgroup listing.

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------
[root@localhost samba]# 

w10下添加网络位置

方式一: 我的电脑 -> \10.8.204.189, 就会出现前面配置的分享列表
方式二: 我的电脑 -> 添加网络映射 -> 输入网络地址: \192.168.1.5\root

然后使用root和设置的smb密码登陆

你可能感兴趣的:(安装samba)