samba案例配置
1、安装samba服务,
rpm安装所需包:perl-Convert-ASN1(依赖包)、samba(服务进程)、samba-common(配置文件),samba-client(smb-client客户端)。
2、小案例配置
要求:
a、samb使用user安全级别,创建三个共享目录,/home/samba,/tmp/user1,/tmp/user2;
b、/home/samba的共享名为public,smb用户对其有可读权限,/tmp/user1为user1的共享共享目录,/tmp/user2为user2的共享目录。
a、配置:
#vim /etc/samba/smb.conf
#======================= Global Settings =============
workgroup = MYGROUP
server string = Samba Server Version %v
interfaces = 192.168.2.1/24
bind interfaces only =YES #绑定server监听的ip
hosts allow = 127. 192.168.2. #仅允许127.0.0.0、192.168.2.0网段访问
log file = /var/log/samba/%m.log
#======================= Share Definitions ============
[public]
comment = Public's samba directory
path = /home/samba
public = yes
writable = no
[user1] #共享名
comment = this is user1's samba directory #描述
path = /tmp/user1 #物理路径
public = no
writable = yes #可写
write list = user1 #可写用户
[user2]
comment = this is user1's samba directory
path = /tmp/user2
public = no
writable = yes
valid users = user2 #有效用户
b、创建用户
#useradd user1
#echo "123" | passwd --stdin user1
#useradd user2
#echo "123" | passwd --stdin user2
c、创建目录,并修改所有者
chown user1.user1 /tmp/user1
chown user2.user2 /tmp/user2
echo "test1" > /tmp/user1/user1.txt
echo "test2" > /tmp/user2/user2.txt
测试,
user1不可访问user2的目录,
user2可以访问user1的目录,但仅有读取权限,和执行权限
3、挂载samba共享的各种方式:
手动挂载:
[root@client tmp]# mkdir abc
[root@client tmp]# mount -t cifs //192.168.2.1/public /tmp/abc -o username=user1
[root@client abc]# cd /tmp/abc/
[root@client abc]# ll
总计 0
drwxr-xr-x 2 root root 0 12-19 17:20 public
-rw-r--r-- 1 root root 0 12-19 17:20 public.txt
mount (rw,)但是并不能创建修改目录或文件,仅有可读权限,
smb服务器端,public共享的权限值为仅可读。
不理解,为什么挂载时还是显示rw呢,
2、开机自动挂载
#vim /etc/fstab
//192.168.2.1/public /tmp/abc cifs defaults,username=user1 0 0
[root@client tmp]# mount -a
Password:
或//192.168.2.1/public /tmp/abc cifs defaults,username=user1,password=123 0 0
[root@client tmp]# mount -a
3、为保证用户账号及密码安全,将账号与密码存放在可读的文件中
//192.168.2.1/public /tmp/abc cifs defaults,credentials=/etc/samba/pwd.txt 0 0
#vim /etc/samba/pwd.txt (以username,password为关键字进行读取,可以写多个用户,第一个用户可以,就直接挂载了)
username=user1
password=123
#chmod 400 /etc/samba/pwd.txt
4、为节约带宽,设置超时后,自动卸载
#vim /etc/auto.master
/home /etc/smb.misc --timeout=05
#vim /etc/smb.misc
smb -fstype=cifs,credentials=/etc/samba/pwd.txt ://192.168.2.1/public
:wq
#vim /etc/samba/pwd.txt
username=user1
password=123
# service autofs start
4、访问windows共享
1、创建共享文件smb
2、开机guest账户