samba服务的自动安装脚本

说明

搬运其他社区自己写的

https://bbs.leyuxyz.com/t/243703

直接写了个自动化的shell脚本,是Ubuntu系统用的,其他系统自己修改。Samba自身支持IPV6。

内容

#!/bin/bash

# 安装 Samba
sudo apt update -y
sudo apt install -y samba

# 备份并配置 Samba
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
sudo tee -a /etc/samba/smb.conf >/dev/null <<EOF
[shared_folder]
    path = /home/shared_folder
    available = yes
    valid users = user1,user2
    read only = no
    browseable = yes
    public = yes
    writable = yes
EOF

# 创建共享文件夹
sudo mkdir -p /home/shared_folder

# 设置共享文件夹权限
sudo chown nobody:nogroup /home/shared_folder
sudo chmod 777 /home/shared_folder

# 添加用户并设置密码
users=("user1" "user2")

for user in "${users[@]}"; do
    read -s -p "Enter password for ${user}: " password
    echo
    read -s -p "Confirm password for ${user}: " confirm_password
    echo

    if [[ "${password}" != "${confirm_password}" ]]; then
        echo "Passwords do not match. Please try again."
        exit 1
    fi

    sudo useradd -m "${user}"
    echo -e "${password}\n${password}" | sudo smbpasswd -s -a "${user}"
done

# 重启 Samba 服务
sudo systemctl restart smbd.service
posted @ 2025-12-17 15:02  杨旭0324  阅读(2)  评论(0)    收藏  举报