应用系统环境说明:
Ubuntu16.04
uname -a
Linux <ServerName> 4.15.0-45-generic #48~16.04.1-Ubuntu SMP <Date_Info> UTC <Year_Info> x86_64 x86_64 x86_64 GNU/Linux
阿里云软件源
sudo vim /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu xenial-security main restricted
deb http://security.ubuntu.com/ubuntu xenial-security universe
deb http://security.ubuntu.com/ubuntu xenial-security multiverse
开始部署:
一、安装samba服务
sudo apt -y install samba samba-common
二、创建必要的文件目录
sudo mkdir -p /srv/ftp/<Private> && sudo mkdir -p /srv/ftp/<Public>
三、创建私有用户
sudo adduser <Username>
四、修改私有目录所属用户
sudo chown <Username>: /srv/ftp/<Username>
五、设置私有用户为smb账户
(echo <Password>;echo Password) | sudo smbpasswd -a <Username>
六、编辑配置文件
sudo vim /etc/samba/smb.conf
[<Private_Name_of_SMB>]
? ? comment = <Private>‘s Data
? ? path = /srv/samba/<Private_Directory>
? ? guest ok = no
? ? browseable = no
? ? create mask = 0700
? ? directory mask = 0700
? ? read only = no
[<Public_Name_of_SMB>]
? ? comment = Public‘s Data
? ? path = /srv/samba/<Public_Directory>
? ? browseable = yes
? ? create mask = 0755
? ? writable = yes
七、重启服务,使配置文件生效
sudo systemctl restart smbd.service
验证服务状态:
netstat -vatunp | grep 445
(Not all processes could be identified, non-owned process info
?will not be shown, you would have to be root to see it all.)
tcp ? ? ? ?0 ? ? ?0 0.0.0.0:445? ? ? ? ? ? ? 0.0.0.0:* ? ? ? ? ? ? ? LISTEN ? ? ?-
sudo systemctl status smbd.service
● smbd.service - LSB: start Samba SMB/CIFS daemon (smbd)
? ?Loaded: loaded (/etc/init.d/smbd; bad; vendor preset: enabled)
? ?Active: active (running) since <Date_Info> CST; <Duration_Time>
? ? ?Docs: man:systemd-sysv-generator(8)
? Process: 209885 ExecReload=/etc/init.d/smbd reload (code=exited, status=0/SUCC
? ? Tasks: 12
? ?Memory: 50.1M
? ? ? CPU: 49min 23.994s
? ?CGroup: /system.slice/smbd.service
连接测试:
一、Windows终端cmd
::关闭所有已启用的磁盘映射
net use * /delete /y > nul
::创建新的映射设置卷标为V
net use V: \\<ServerIP>\<Private> <Password> /user:<Username> /persistent:no > nul
::打开映射目录
start V:\
二、Linux终端Bash
#创建挂载目录
sudo mkdir /mnt/smb
#临时挂载
sudo mount -t cifs -o username=<Username>,password=<Password>,vers=1.0 //<ServerIP>/<Private_Name_of_SMB> /mnt/smb
#进入共享目录
cd /mnt/smb