# samba服务自动挂载 **服务端** 安装samba ``` [root@localhost ~]# yum install samba ``` 编辑主配置文件 ``` [root@localhost ~]# vim /etc/samba/smb.conf [hwx] comment = h path = /storage write list = A valid list = A,B ``` 创建samba用户 ``` [root@localhost ~]# useradd A [root@localhost ~]# useradd B [root@localhost ~]# smbpasswd -a A New SMB password: Retype new SMB password: Added user A. [root@localhost ~]# smbpasswd -a B New SMB password: Retype new SMB password: Added user B. ``` 创建共享文件夹 ``` [root@localhost ~]# mkdir /storage [root@localhost ~]# chmod 777 /storage ``` 加入开机自启动项,重启服务 ``` [root@localhost ~]# systemctl enable smb Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service. [root@localhost ~]# systemctl enable nmb Created symlink from /etc/systemd/system/multi-user.target.wants/nmb.service to /usr/lib/systemd/system/nmb.service. [root@localhost ~]# systemctl restart smb [root@localhost ~]# systemctl restart nmb ``` **客户端** 安装samba-client ``` yum install smba-client ``` 连接samba服务器 ``` [root@localhost ~]# smbclient //samba.hb.com/hwx -U A Enter SAMBA\A's password: Try "help" to get a list of possible commands. smb: \> exit ``` 创建挂载目录并写上自动挂载 ``` [root@localhost ~]# mkdri -p /htdocs -bash: mkdri: command not found [root@localhost ~]# chmod 777 /htdocs/ [root@localhost ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Sat Mar 6 02:13:19 2021 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/centos-root / xfs defaults 0 0 UUID=e0b39157-f22b-43a5-979d-bbb092490d01 /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 /dev/sr0 /dzz/cdrom iso9660 defaults 0 0 //samba.hb.com/hwx /htdocs cifs rw,username=A,password=123 0 0 ``` 安装服务 ``` [root@localhost ~]# yum install cifs-utils.x86_64 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Package cifs-utils-6.2-10.el7.x86_64 already installed and latest version Nothing to do ``` 挂载 ``` [root@localhost ~]# mount -a [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 475M 0 475M 0% /dev tmpfs 487M 0 487M 0% /dev/shm tmpfs 487M 7.7M 479M 2% /run tmpfs 487M 0 487M 0% /sys/fs/cgroup /dev/mapper/centos-root 17G 1.4G 16G 8% / /dev/sr0 4.4G 4.4G 0 100% /dzz/cdrom /dev/sda1 1014M 138M 877M 14% /boot tmpfs 98M 0 98M 0% /run/user/0 //samba.hb.com/hwx 17G 1.4G 16G 9% /htdocs ```
最后修改:2021 年 11 月 29 日
如果觉得我的文章对你有用,欢迎打赏