文件共享之samba
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: \>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.