1.samba作用:
提供cifs协议实现共享文件,
2.安装
[root@desktop ~]# yum install samba samba-common samba-client -y
samba 主服务
samba-common 命令
samba-client 客户测试
[root@desktop ~]# systemctl start smb nmb ##启动服务
[root@desktop ~]# systemctl enable smb nmb
ln -s '/usr/lib/systemd/system/smb.service' '/etc/systemd/system/multi-user.target.wants/smb.service'
ln -s '/usr/lib/systemd/system/nmb.service' '/etc/systemd/system/multi-user.target.wants/nmb.service'
3.添加samba用户
smb用户必须是本地用户
[root@desktop ~]# smbpasswd -a student ##添加student用户(该用户在本地用户中)
New SMB password:
Retype new SMB password:
Added user student.
[root@desktop ~]# pdbedit -L ##查询用户是否建立成功
student:1000:Student User
4.文件共享
****共享用户家目录****
[root@desktop ~]# setsebool -P samba_enable_home_dirs on ##在selinux中设定smb用户可以访问自己家目录
[root@desktop ~]# smbclient //172.25.254.140/student -U student ##登录smb用户student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Thu Jul 10 19:06:52 2014
.. D 0 Thu Jul 10 18:19:09 2014
.bash_logout H 18 Wed Jan 29 07:45:18 2014
.bash_profile H 193 Wed Jan 29 07:45:18 2014
.bashrc H 231 Wed Jan 29 07:45:18 2014
.ssh DH 0 Thu Jul 10 18:19:10 2014
.config DH 0 Thu Jul 10 19:06:53 2014
40913 blocks of size 262144. 28549 blocks available
smb: \>
****共享新建目录时****
[root@desktop ~]# mkdir /biubiubiu
[root@desktop ~]# touch /biubiubiu/lilili
[root@desktop ~]# vim /etc/samba/smb.conf ##编写主配置文件,在末尾添加
[haha]
comment = local
path = /biubiubiu
[root@desktop ~]# setsebool -P samba_enable_home_dirs 0 ##关闭smb用户对用户家目录的访问
[root@desktop ~]# smbclient //172.25.254.140/haha -U student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
NT_STATUS_ACCESS_DENIED listing \*
smb: \> ^C
[root@desktop ~]# semanage fcontext -a -t samba_share_t '/biubiubiu(/.*)?'
[root@desktop ~]# restorecon -RvvF /biubiubiu
restorecon reset /biubiubiu context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /biubiubiu/lilili context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
[root@desktop ~]# smbclient //172.25.254.140/haha -U student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Sat Jun 3 02:26:47 2017
.. D 0 Sat Jun 3 02:26:11 2017
lilili N 0 Sat Jun 3 02:26:47 2017
40913 blocks of size 262144. 28548 blocks available
smb: \>
****共享系统目录时****
[root@desktop ~]# vim /etc/samba/smb.conf
[haha]
comment = local
path = /mnt
[root@desktop ~]# touch /mnt/file{1..9}
[root@desktop ~]# setsebool -P samba_export_all_ro on ##只读共享
[root@desktop ~]# setsebool -P samba_export_all_rw on ##读写共享
[root@desktop ~]# smbclient //172.25.254.140/haha -U student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Sat Jun 3 02:41:31 2017
.. D 0 Sat Jun 3 02:26:11 2017
file1 N 0 Sat Jun 3 02:41:31 2017
file2 N 0 Sat Jun 3 02:41:31 2017
file3 N 0 Sat Jun 3 02:41:31 2017
file4 N 0 Sat Jun 3 02:41:31 2017
file5 N 0 Sat Jun 3 02:41:31 2017
file6 N 0 Sat Jun 3 02:41:31 2017
file7 N 0 Sat Jun 3 02:41:31 2017
file8 N 0 Sat Jun 3 02:41:31 2017
file9 N 0 Sat Jun 3 02:41:31 2017
40913 blocks of size 262144. 28549 blocks available
smb: \>
提供cifs协议实现共享文件,
2.安装
[root@desktop ~]# yum install samba samba-common samba-client -y
samba 主服务
samba-common 命令
samba-client 客户测试
[root@desktop ~]# systemctl start smb nmb ##启动服务
[root@desktop ~]# systemctl enable smb nmb
ln -s '/usr/lib/systemd/system/smb.service' '/etc/systemd/system/multi-user.target.wants/smb.service'
ln -s '/usr/lib/systemd/system/nmb.service' '/etc/systemd/system/multi-user.target.wants/nmb.service'
3.添加samba用户
smb用户必须是本地用户
[root@desktop ~]# smbpasswd -a student ##添加student用户(该用户在本地用户中)
New SMB password:
Retype new SMB password:
Added user student.
[root@desktop ~]# pdbedit -L ##查询用户是否建立成功
student:1000:Student User
4.文件共享
****共享用户家目录****
[root@desktop ~]# setsebool -P samba_enable_home_dirs on ##在selinux中设定smb用户可以访问自己家目录
[root@desktop ~]# smbclient //172.25.254.140/student -U student ##登录smb用户student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Thu Jul 10 19:06:52 2014
.. D 0 Thu Jul 10 18:19:09 2014
.bash_logout H 18 Wed Jan 29 07:45:18 2014
.bash_profile H 193 Wed Jan 29 07:45:18 2014
.bashrc H 231 Wed Jan 29 07:45:18 2014
.ssh DH 0 Thu Jul 10 18:19:10 2014
.config DH 0 Thu Jul 10 19:06:53 2014
40913 blocks of size 262144. 28549 blocks available
smb: \>
****共享新建目录时****
[root@desktop ~]# mkdir /biubiubiu
[root@desktop ~]# touch /biubiubiu/lilili
[root@desktop ~]# vim /etc/samba/smb.conf ##编写主配置文件,在末尾添加
[haha]
comment = local
path = /biubiubiu
[root@desktop ~]# setsebool -P samba_enable_home_dirs 0 ##关闭smb用户对用户家目录的访问
[root@desktop ~]# smbclient //172.25.254.140/haha -U student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
NT_STATUS_ACCESS_DENIED listing \*
smb: \> ^C
[root@desktop ~]# semanage fcontext -a -t samba_share_t '/biubiubiu(/.*)?'
[root@desktop ~]# restorecon -RvvF /biubiubiu
restorecon reset /biubiubiu context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /biubiubiu/lilili context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
[root@desktop ~]# smbclient //172.25.254.140/haha -U student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Sat Jun 3 02:26:47 2017
.. D 0 Sat Jun 3 02:26:11 2017
lilili N 0 Sat Jun 3 02:26:47 2017
40913 blocks of size 262144. 28548 blocks available
smb: \>
****共享系统目录时****
[root@desktop ~]# vim /etc/samba/smb.conf
[haha]
comment = local
path = /mnt
[root@desktop ~]# touch /mnt/file{1..9}
[root@desktop ~]# setsebool -P samba_export_all_ro on ##只读共享
[root@desktop ~]# setsebool -P samba_export_all_rw on ##读写共享
[root@desktop ~]# smbclient //172.25.254.140/haha -U student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Sat Jun 3 02:41:31 2017
.. D 0 Sat Jun 3 02:26:11 2017
file1 N 0 Sat Jun 3 02:41:31 2017
file2 N 0 Sat Jun 3 02:41:31 2017
file3 N 0 Sat Jun 3 02:41:31 2017
file4 N 0 Sat Jun 3 02:41:31 2017
file5 N 0 Sat Jun 3 02:41:31 2017
file6 N 0 Sat Jun 3 02:41:31 2017
file7 N 0 Sat Jun 3 02:41:31 2017
file8 N 0 Sat Jun 3 02:41:31 2017
file9 N 0 Sat Jun 3 02:41:31 2017
40913 blocks of size 262144. 28549 blocks available
smb: \>