@
目录服务端部署环境:Ubuntu22
客户端环境;centos7
samba文件服务器
安装samba服务
apt install -y samba
创建一个共享文件夹,并放开权限
mkdir /opt/share
chmod 777 /opt/share/
创建samba用户并设置密码
注意要先创建一个Ubuntu用户来指定,或者使用以及存在的用户
useradd smb-test
-a 指定用户,输入密码后回车
smbpasswd -a smb-test
修改配置文件
vim /etc/samba/smb.conf
常见配置参数详解
[temp] #共享资源名称
comment = Temporary file space #简单的解释,内容无关紧要
path = /tmp #实际的共享目录
writable = yes #设置为可写入
browseable = yes #可以被所有用户浏览到资源名称,
guest ok = yes #可以让用户随意登录
public = yes #允许匿名查看
valid users = 用户名 #设置访问用户
valid users = @组名 #设置访问组
readonly = yes #只读
readonly = no #读写
hosts deny = 192.168.0.0 #表示禁止所有来自192.168.0.0/24 网段的IP 地址访问
hosts allow = 192.168.0.24 #表示允许192.168.0.24 这个IP 地址访问
cat >> /etc/samba/smb.conf << eof
[my-samba]
comment = hello
path = /opt/share/
writable = yes
browseable = yes
public = yes
readonly = no
eof
启动samba
systemctl restart smbd
windows测试
windows下 win+r 进行访问 Ubuntu地址
输入创建的smb用户和密码
创建一个文件进行测试
mkdir -p /opt/share/hello
centos测试挂载
安装客户端所需安装包
yum install cifs-utils -y
yum install -y samba-client samba-common
创建挂载点
mkdir /mnt/smb-test
查看挂载点
[root@huhy ~]# smbclient -L //192.168.200.160
Enter SAMBA\root's password:
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
my-samba Disk hello
IPC$ IPC IPC Service (huhy server (Samba, Ubuntu))
Reconnecting with SMB1 for workgroup listing.
smbXcli_negprot_smb1_done: No compatible protocol selected by server.
protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE
Unable to connect with SMB1 -- no workgroup available
开始挂载,注意挂载的不是路径而是挂载点的名称my-samba
1,如果报错找不到文件,多半是挂载服务端的名称错了
2,如果报权限问题,多半没有给服务端挂载路径777权限
mount -t cifs //192.168.200.160/my-samba /mnt/smb-share -o username=smb-test
[root@huhy ~]# mount -t cifs //192.168.200.160/my-samba /mnt/smb-share -o username=smb-test
Password for smb-test@//192.168.200.160/my-samba: ******
[root@huhy ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 12M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 50G 1.5G 49G 3% /
/dev/mapper/centos-home xfs 46G 33M 46G 1% /home
/dev/sda1 xfs 1014M 151M 864M 15% /boot
tmpfs tmpfs 378M 0 378M 0% /run/user/0
//192.168.200.160/my-samba cifs 20G 8.1G 12G 42% /mnt/smb-share
[root@huhy ~]#
测试
centos客户端
touch /mnt/smb-share/hello-smb
ubuntu服务端
root@huhy:~# ll /opt/share/
total 12
drwxrwxrwx 3 root root 4096 Nov 2 14:35 ./
drwxr-xr-x 3 root root 4096 Nov 2 13:14 ../
drwxr-xr-x 2 root root 4096 Nov 2 13:48 hello/
-rwxr--r-- 1 smb-test smb-test 0 Nov 2 14:35 hello-smb*
root@huhy:~#
ubuntu脚本一键部署
#!bin/bash
username=smb-test
apt install -y samba
mkdir /opt/share
chmod 777 /opt/share/
useradd $username
smbpasswd -a $username
cat >> /etc/samba/smb.conf << eof
[my-samba]
comment = hello
path = /opt/share/
writable = yes
browseable = yes
public = yes
readonly = no
eof
systemctl restart smbd
标签:samba,部署,一键,share,192.168,test,root,smb
From: https://www.cnblogs.com/hwiung/p/16855075.html