Linux中安装使用samba

Linux中安装使用samba

文件共享服务器-----服务器端/客户端模式,服务端—Linux客户端-----windows客户端,使用端口号TCP
协议的139与445,UDP协议137端口。
与NFS不同的是可以实现共享文件,可以远程传输。

在服务器端下载samba

[root@mail ~]#  yum -y install samba

添加用户,并提供shell
将用户CSDN_share添加入samba用户中

[root@mail ~]# useradd -s /sbin/nolongin CSDN_share
[root@mail ~]# smbpasswd -a CSDN_share
输入密码
New SMB password:
Retype new SMB password:
Added user CSDN_share.

创建共享文件夹,并更改文件夹权限

[root@mail ~]# mkdir /storage/CSDN_share
[root@mail ~]# chmod -Rf 777 /storage/CSDN_share/

编辑samba配置文件

[root@mail ~]# vim /etc/samba/smb.conf
添加用户名称
[CSDN_share]
        comment = CSDN_share   描述
        path = /storage/CSDN_share   路径
        browseable = yes   是否可见
        writable = yes     是否可写
        guest ok = yes     是否匿名登录

重启samba服务,并设置开机启动samba

[root@mail ~]# systemctl restart smb
[root@mail ~]# systemctl enable smb

关闭防火墙或者开启之后配置samba服务

[root@mail ~]# systemctl restart firewalld
[root@mail ~]# firewall-cmd --permanent --add-service=samba

关闭SElinux,若SElinux开启则无法正常访问

[root@mail ~]# getenforce
Disabled

查看SELinux当前运行状态
[root@localhost ~]# getenforce
Enforcing
#Enforcing = 1 Permissive = 0
临时关闭SELinux,立即生效。
[root@localhost ~]# setenforce 0
永久关闭SELinux,重启生效。
[root@localhost ~]# vim /etc/selinux/config
修改内容
将第7行 SELINUX=enforcing 修改为SELINUX=disabled

客户端ping服务器看是否可以正常通信,不可正常通信需要检查虚拟机网络配置
vim /etc/sysconfig/network-scripts/ifcfg-ens32 中配置

[root@cj-host-02 ~]# ping 172.16.10.10
PING 172.16.10.10 (172.16.10.10) 56(84) bytes of data.
64 bytes from 172.16.10.10: icmp_seq=1 ttl=64 time=0.460 ms
64 bytes from 172.16.10.10: icmp_seq=2 ttl=64 time=0.529 ms

查看远程目录是否存在,-L是位置-U是用户名%后面跟密码

[root@cj-host-02 ~]# smbclient -L //172.16.10.10 -U CSDN_share%123

	Sharename       Type      Comment
	---------       ----      -------
	print$          Disk      Printer Drivers
	smb_cj          Disk      smb_cj
	CSDN_share      Disk      CSDN_share
	IPC$            IPC       IPC Service (Samba 4.10.16)
	CSND_share      Disk      Home Directories
Reconnecting with SMB1 for workgroup listing.

	Server               Comment
	---------            -------

	Workgroup            Master
	---------            -------

登录共享文件界面

[root@cj-host-02 ~]# smbclient -U CSDN_share%123 //172.16.10.10/CSDN_share
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Mon Nov 22 01:07:12 2021
  ..                                  D        0  Mon Nov 22 01:07:12 2021

		38770180 blocks of size 1024. 33867472 blocks available
smb: \> 

ls 查看

put 上传 命令格式:put 本地文件 远端文件

get 下载 命令格式:get 远端文件 本地文件

quit 退出

编辑/etc/fstab文件,实现开机自动挂载

[root@localhost ~]# echo "//172.16.10.10/CSDN_share /media/CSDN_share cifs
username=CSDN_share,password=123,_netdev 0 0" >> /etc/fstab

挂载

[root@localhost ~]# mount -a

报错提示

[root@cj-host-02 ~]# smbclient -L //172.16.10.10 -U CSDN_share%123
session setup failed: NT_STATUS_LOGON_FAILURE

未添加samba用户名,或者添加错误导致客户端未查找到用户
检查服务器用户配置

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ACHAI:)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值