Samba简介
Samba是一个用于在Linux和UNIX系统之间共享文件和打印服务的开源软件,它实现了CIFS(Common Internet File System,通用互联网文件系统)协议,允许用户通过网络访问其他计算机上的文件和资源,Samba服务器可以在本地或远程计算机上运行,客户端可以是Windows、macOS或其他类Unix系统。
搭建Samba服务器
1、安装Samba
在Ubuntu或Debian系统中,可以使用以下命令安装Samba:
sudo apt-get update sudo apt-get install samba samba-common-bin
在CentOS或RHEL系统中,可以使用以下命令安装Samba:
sudo yum install samba samba-common
2、配置Samba服务器
编辑Samba配置文件/etc/samba/smb.conf
,可以使用文本编辑器如vi
或nano
:
sudo vi /etc/samba/smb.conf
在配置文件中,可以设置以下参数:
workgroup
:工作组名称,与Windows系统的工作组名称保持一致。
server string
:服务器描述信息。
security
:安全模式,可以设置为user(用户验证)或share(共享验证)。
encrypt passwords
:是否加密密码,建议设置为yes。
map to guest account
:是否将所有匿名访问映射到guest账户,建议设置为yes。
max log size
:日志最大大小,单位为KB。
log file
:日志文件路径。
netbios name
:网络基本输入输出系统(NetBIOS)名称,用于在同一局域网内的计算机之间识别。
dns proxy
:是否使用DNS代理进行域名解析,建议设置为no。
client signing
:是否允许客户端签名请求,建议设置为yes。
client use spnego
:是否允许客户端使用SPNEGO进行身份验证,建议设置为yes。
client ntlmCDN auth
:是否启用NTLMCDN认证,建议设置为yes。
client anonymization
:是否启用匿名访问,建议设置为no。
force user = nobody
:强制使用nobody用户作为匿名访问的用户,默认情况下,Samba会创建一个名为smbserver的用户作为匿名访问的用户。
以下配置表示使用user验证模式,并禁用匿名访问:
[global] workgroup = WORKGROUP server string = Samba Server %v security = user encrypt passwords = yes map to guest account = no max log size = 10000 log file = /var/log/samba/%m.log netbios name = centos dns proxy = no client signing = yes client use spnego = yes client ntlmCDN auth = yes client anonymization = no force user = nobody
3、创建共享目录
在需要共享的目录下创建一个名为.smbfolder
的隐藏文件夹,
mkdir myshare && cd myshare && touch file.txt && chmod a+rw myshare && sudo mv myshare /srv/samba/myshare && sudo chmod a+rwx /srv/samba/myshare && sudo chmod a+w /etc/samba/smb.conf && sudo systemctl restart smbd && sudo systemctl enable smbd
4、添加用户权限
创建一个名为myuser
的用户,并为其分配读写权限:
sudo adduser myuser && sudo usermod --home-dir=/home/myuser --shell=/bin/bash myuser && sudo usermod --append --groups=cdrom myuser && echo "myuser" | sudo chpasswd && sudo nano /etc/samba/smb.conf && echo '[myshare]' | sudo tee --append --force $' path = /srv/samba/myshare valid users = myuser read only = no mbcryp password = yes ' && sudo systemctl restart smbd && sudo systemctl enable smbd && sudo kdestroy && sudo newusers && sudo passwd myuser && sudo su myuser && cd ~ && sudo nano ~.bash_profile && echo 'export HOME=~/Documents' >> ~.bash_profile && source ~.bash_profile && exit && sudo umount /dev/cdrom0 && sudo umount /run/media/* && sudo umount /run/media/usb0/* && sudo umount /run/media/usb1/* && sudo umount /run/media/usb2/* && sudo umount /run/media/usb3/* && sudo umount ~/usb0/* && sudo umount ~/usb1/* && sudo umount ~/usb2/* && sudo umount ~/usb3/* && sudo sync && sudo reboot || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log && exit || echo "Error occurred while setting up Samba server and user" > error.log & sleep infinity & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! & tailf error.log & wait $! &
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/196496.html