欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

搭建Samba

程序员文章站 2024-03-14 15:43:28
...

Centos6 上搭建Samba服务器

#!/bin/sh

sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0

yum install samba -y 

service smb start 

echo "admin " | useradd -s /sbin/nologin admin 

echo "admin " | smbpasswd -a admin

chown admin.admin /root/share

cp /etc/samba/smb.conf /etc/samba/smb.conf_bak
>/etc/samba/smb.conf
cat >>/etc/samba/smb.conf << EOF
[global]
    workgroup = SC.LOCAL
    server string = Samba Server Version %v
    netbios name = NetTrade-File-Server
    log file = /var/log/samba/%m.log
    max log size = 10240
    security = user
    passdb backend = tdbsam
    [shared]
    # 共享文件目录描述
#    comment = Shared Directories
    # 共享文件目录
    path = /root/share/
    # 是否允许guest访问
    public = no
    # 指定管理用户
    admin users = admin
    # 可访问的用户组、用户
    valid users = @admin
    # 是否浏览权限
    browseable = yes
    # 是否可写权限
    writable = yes
    # 文件权限设置
    create mask = 0777
    directory mask = 0777
    force directory mode = 0777
    force create mode = 0777
EOF
service smb restart 
# 设置开机启动
echo "service smb restart" >> /etc/rc.local

# 防止防火墙阻止
/sbin/iptables -I INPUT -p tcp --dport 139 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 445 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/rc.d/init.d/iptables restart

Centos7上搭建Samba服务器

#!/bin/sh

sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0

yum install samba -y 

systemctl start smb

echo "admin " | useradd -s /sbin/nologin admin 

echo "admin " | smbpasswd -a admin

chown admin.admin /root

cp /etc/samba/smb.conf /etc/samba/smb.conf_bak
>/etc/samba/smb.conf
cat >>/etc/samba/smb.conf << EOF
[global]
    workgroup = SC.LOCAL
    server string = Samba Server Version %v
    netbios name = NetTrade-File-Server
    log file = /var/log/samba/%m.log
    max log size = 10240
    security = user
    passdb backend = tdbsam
    [shared]
    # 共享文件目录描述
#    comment = Shared Directories
    # 共享文件目录
    path = /root/
    # 是否允许guest访问
    public = no
    # 指定管理用户
    admin users = admin
    # 可访问的用户组、用户
    valid users = @admin
    # 是否浏览权限
    browseable = yes
    # 是否可写权限
    writable = yes
    # 文件权限设置
    create mask = 0666
    directory mask = 0666
    force directory mode = 0666
    force create mode = 0666
EOF

systemctl enable smb

Ubuntu16

#!/bin/sh

apt-get install samba samba-common -y

systemctl start smbd
systemctl start nmbd

echo "admin " | useradd -s /sbin/nologin admin 

echo "admin " | smbpasswd -a admin

chown admin.admin /root

cp /etc/samba/smb.conf /etc/samba/smb.conf_bak
>/etc/samba/smb.conf
cat >>/etc/samba/smb.conf << EOF
[global]
    workgroup = SC.LOCAL
    server string = Samba Server Version %v
    netbios name = NetTrade-File-Server
    log file = /var/log/samba/%m.log
    max log size = 10240
    security = user
    passdb backend = tdbsam
    [shared]
    # 共享文件目录描述
#    comment = Shared Directories
    # 共享文件目录
    path = /root/
    # 是否允许guest访问
    public = no
    # 指定管理用户
    admin users = admin
    # 可访问的用户组、用户
    valid users = @admin
    # 是否浏览权限
    browseable = yes
    # 是否可写权限
    writable = yes
    # 文件权限设置
    create mask = 0666
    directory mask = 0666
    force directory mode = 0666
    force create mode = 0666
EOF

systemctl enable smbd
systemctl enable nmbd


相关标签: 基础设置 samba