samba服务配置
samba功能:samba可以实现windows和linux服务器之间的数据共享
一、无需用户名和密码共享,只读不可写
1、安装samba
[root@daixuan log]# yum install -y samba samba-client
2、配置samba
[root@daixuan log]# vim /etc/samba/smb.conf
security = share //设置samba共享
workgroup = WORKGROUP //设置工作组为workgroup
[daixuan]
comment = share all //共享所有人
path = /tmp/sambadir //指定samba共享的目录
browseable = yes //允许浏览
public = yes //公开
writable = no //sam共享目录不可写
[root@daixuan log]# mkdir /tmp/sambadir
[root@daixuan log]# cp /etc/passwd /tmp/sambadir/1.txt
[root@daixuan log]# mkdir /tmp/sambadir/test
[root@daixuan log]# chmod 777 !$ //这里test目录权限是777,实际测试仍然不可写writable=no
chmod 777 /tmp/sambadir/test
[root@daixuan log]# smbclient //192.168.101.230
[root@daixuan test]# /etc/init.d/smb start //启动sam服务
3、samba查看共享文件
widnows共享输入:
\\192.168.101.230\daixuan,可以查看到sam共享文件夹
linux查看samba共享:
[root@daixuan log]# smbclient //192.168.101.230/daixuan
WARNING: The security=share option is deprecated
Enter root‘s password: //不用输入密码,直接按enter
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23-21.el6_7]
Server not using user level security and no password supplied.
smb: \> ls
. D 0 Sun Dec 27 13:16:21 2015
.. D 0 Sun Dec 27 13:19:38 2015
test D 0 Sun Dec 27 13:16:21 2015
1.txt 1706 Sun Dec 27 13:15:59 2015 35959 blocks of size 1048576. 30046 blocks available
smb: \>
4、挂载samba共享目录daixuan到/opt目录下,查看共享文件
[root@daixuan log]# yum install -y cifs-utils
[root@daixuan log]# mount -t cifs //192.168.101.230/daixuan /opt/
Password:
[root@daixuan log]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 4.0G 30G 12% /
tmpfs 947M 0 947M 0% /dev/shm
/dev/sda1 190M 30M 151M 17% /boot
/dev/sdb5 2.0G 9.1M 1.9G 1% /mnt
/dev/sdb1 3.0G 75M 2.8G 3% /home/daixuan/123
//192.168.101.230/daixuan 36G 4.0G 30G 12% /opt
二、更改samba共享目录需要用户名和密码验证登录
[root@daixuan test]# vim /etc/samba/smb.conf
security = user //设置samba共享为用户验证登录方式
[daixuanlinux]
comment = share for users
path = /tmp/sambadir
browseable = yes
public = no
writable = yes
[root@daixuan test]# pdbedit -h //查看pdbetit命令
[root@daixuan test]# pdbedit -a smbuser1
new password:
retype new password:
[root@daixuan test]# pdbedit -x smbuser2 //删除smbuser2
[root@daixuan test]# /etc/init.d/smb restart
关闭 SMB 服务: [确定]
启动 SMB 服务: [确定]
[root@daixuan test]# mount -t cifs -o username=smbuser1,password=daixuan //192.168.101.230/daixuanlinux /opt //挂载daixuanlinux共享目录到/opt
[root@daixuan opt]# df -h
//192.168.101.230/daixuanlinux 36G 4.0G 30G 12% /opt
此时windows打开共享daixuanlinux文件夹需要输入用户名和密码,且windows共享中用户可以建立目录和文件。
本文出自 “daixuan” 博客,请务必保留此出处http://daixuan.blog.51cto.com/5426657/1728749
原文:http://daixuan.blog.51cto.com/5426657/1728749