systemctl restart smb.service
semanage fcontext -a -t samba_share_t '/yang(/.*)?' ##修改安全上下文只对,该目录有效。故保证ypa目录也可被访问,则需要修改selinux里面的
restorecon -FvvR //
smbclient //172.25.254.124/yang -U student
smbclient //172.25.254.124/yang -U student
Enter student's password:
Domain=[LINUXJET]('此处名字修改,即为主配置文件中22行的修改变量') OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Fri Mar 17 22:13:45 2017
.. D 0 Fri Mar 17 22:13:52 2017
40913 blocks of size 262144. 28546 blocks available
smb: \>
smbclient //172.25.254.124/ypa -U student
getsebool -a | grep samba
setsebool -P samba_export_all_rw on ##修改读写权限,包括系统目录及自建目录。这个开启后就与文件的安全上下文无关
[root@samba student]# smbclient -L //172.25.254.124 -U student
Enter student's password:
Domain=[LINUXJET] OS=[Unix] Server=[Samba 4.1.1]
Sharename Type Comment
--------- ---- -------
yang Disk this is myself mkdir
ypa Disk this is ypa
IPC$ IPC IPC Service (Samba Server Version 4.1.1)
student Disk Home Directories
Domain=[LINUXJET] OS=[Unix] Server=[Samba 4.1.1]
Server Comment
--------- -------
Workgroup Master
--------- -------
1.3 samba 匿名访问
vim /etc/samba/smb.conf
....
125 map to guest = bad user ##允许匿名用户访问321 [yang]
322 comment = thisis myself mkdir ##说明323 path = /yang ##指定共享目录324 guest ok = yes##允许匿名用户访问
....
systemctl restart smb.service
mount //172.25.254.124/yang /mnt/ -o username=guest
df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3156972 7316928 31% /
devtmpfs 481120 0 481120 0% /dev
tmpfs 496708 140 496568 1% /dev/shm
tmpfs 496708 13036 483672 3% /run
tmpfs 496708 0 496708 0% /sys/fs/cgroup
//172.25.254.124/yang 10473900 3156972 7316928 31% /mnt
cd /mnt/
ls -a
1.4 samba共享目录的管理参数
vim /etc/samba/smb.conf
321 [yang]
322 comment = localdirectory yang
323 path = /yang
324 guest ok = yes
325 writable = yes ##所有人可写326#write list = yang ##列表中的人可写327#write list = +yang ##列表中的组可写328#valid users = yang ##允许登陆的人329#valid users = @yang ##允许登陆的组330#browseable = yes ##是否隐藏,yes不隐藏331#admin users = yang ##允许某用户以超户操作
测试
mount //172.25.254.125/yang /mnt/ -o password=aaa,username=student
1.5 samba多用户认证,多用户挂载
yum install cifs-utils
vim /root/passfile
username=smb用户
password=smb用户密码
mount //172.25.254.125/yang /mnt/ -o credentials=/root/passfile,multiuser,sec=ntlmssp ##多用户挂载
su - yang ##与smb用户同名
ls /mnt
cifscreds add 172.25.254.125
ls /mnt 查看成功
su - test
ls /mnt
cifscreds add 172.25.254.125
ls /mnt ##依然不成功
/> /backstores/block create yang:si /dev/vdb1 ##创建块文件与/dev/vdb1关联
Created block storage object yang:si using /dev/vdb1.
/> /iscsi create iqn.2017-03.com.yang:si ##创建iqn
Created target iqn.2017-03.com.yang:si.
Created TPG 1.
/> /iscsi/iqn.2017-03.com.yang:si/tpg1/acls create iqn.2017-03.com.yang:key1 ##创建钥匙文件
Created Node ACL for iqn.2017-03.com.yang:key1
/> /iscsi/iqn.2017-03.com.yang:si/tpg1/luns create /backstores/block/yang:si ##关联iqn与块文件
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2017-03.com.yang:key
/> /iscsi/iqn.2017-03.com.yang:si/tpg1/portals create 172.25.254.125 ##开放ip共享
Using default IP port 3260
Created network portal 172.25.254.125:3260.
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json