1.在Ubuntu中下载samba
apt install samba
apt install smbclient
2.修改samba对应的配置文件,在/etc/samba/smb.conf中添加:
security = share
[share]
comment = share folder
browseable = yes
path = /root
create mask = 0777
directory mask = 0777
valid users = yanghua
force user = nobody
force group = nogroup
public = yes
available = yes
write list =yanghua
重点注意path必须在你的Ubuntu中存在;valid users 必须为Ubuntu系统中已有的用户;
3.为新的samba用户添加密码:
smbpasswd -a yanghua
4.重启samba服务:
service samba restart
5.关闭系统防火墙
ufw disable
6.将你的共享目录的权限设置为777,我这里为/root目录
chmod 777 /root
7.在windows中访问共享文件夹/root,完成访问
8.smbclient的常用命令:
1>查询对应ip主机下的共享文件夹有哪些
smbclient -L //192.168.1.113
2>以用户名和密码登录samba服务器
smbclient //192.168.1.113/share -U username%passwd
3>进入smb命令行后可以使用ls、cd、get、put等命令常用的为上传操作put和下载操作get。
将samba服务器上的a,c复制到本地/home下,取名为a.txt:
get a.c /home/a.txt
将本地的samba配置文件复制到samba服务器上:
put /etc/samba/smb.conf smbconf
4>在linux中挂载samba服务器上的文件系统
mount -t cifs -o username=yanghua,password=261797yh //192.168.1.113/share /mnt/hgfs
取消挂载:
umount /mnt/hgfs/