samba服務
SMB(Server Messages Block,資訊服務塊)是一種在區域網路上共享檔案和列印機的一種通信協定,它為區域網路内的不同計算機之間提供檔案及列印機等資源的共享服務
安裝samba服務
配置設定IP,安裝yum源
<a href="https://s2.51cto.com/wyfs02/M02/9E/B0/wKioL1mUZrCDHRj8AABNc6FmCeo785.png" target="_blank"></a>
<a href="https://s2.51cto.com/wyfs02/M02/9E/B0/wKioL1mUabTBj_lpAABw6iUDkoI189.png" target="_blank"></a>
<a href="https://s3.51cto.com/wyfs02/M00/9E/B0/wKioL1mUZrGxB-XCAAG-qxuPjaw738.png" target="_blank"></a>
安裝samba服務,并啟動服務
yum install samba samba-common samba-client -y
systemctl start smb
systemctl enable smb
<a href="https://s1.51cto.com/wyfs02/M02/9E/B0/wKioL1mUZwvyQsS3AACQ4Cpz3xU815.png" target="_blank"></a>
過濾檢視samba服務所開的端口
列出ip為225這台主機所共享的檔案
<a href="https://s1.51cto.com/wyfs02/M01/9E/B0/wKioL1mUZ3ag0W_kAAD2281kPEY247.png" target="_blank"></a>
建立samba使用者(這個使用者必須是主機中已有的使用者)
smbpasswd -a student
New SMB password: #輸入smb目前使用者密碼
Retype new SMB password: #确認密碼
<a href="https://s3.51cto.com/wyfs02/M01/9E/B0/wKioL1mUaE-jipKOAADfAGGw4eY167.png" target="_blank"></a>
pdbedit -L #檢視smb使用者資訊
pdbedit -x smb使用者 #删除smb使用者
<a href="https://s5.51cto.com/wyfs02/M00/9E/B0/wKioL1mUaKGiSXxWAAA2CnGZs1Y730.png" target="_blank"></a>
由于有selinux這個核心級超級防火牆的存在,直接登陸通路權限會被拒,是以要關閉selinux或者設定selinux中的權限開放,推薦使用第二種方法,因為這樣會更加安全
setsebool -P enable_samba_home_dirs on ##在selinux中設定smb使用者可以通路自己的家目錄
<a href="https://s3.51cto.com/wyfs02/M02/9E/B0/wKioL1mUaWujMGaMAAELm9oMs_c798.png" target="_blank"></a>
<a href="https://s3.51cto.com/wyfs02/M00/9E/B0/wKioL1mUaWuiA81FAACu6JtzYCc669.png" target="_blank"></a>
以student使用者身份登入登陸sabmba列出共享内容
<a href="https://s5.51cto.com/wyfs02/M00/9E/B0/wKioL1mUacvgriUIAADotz8eF8w202.png" target="_blank"></a>
vim /etc/samba/smb.conf
設定主配置檔案,允許/拒絕挂載的主機
<a href="https://s3.51cto.com/wyfs02/M01/9E/B0/wKioL1mUamaxXDMiAAC6LGES5Sg783.png" target="_blank"></a>
hosts deny ##使用者黑名單,此名單使用者不能挂載主機共享的檔案
hosts allow ##使用者白名單,此名單使用者可以挂載使用主機共享的檔案
<a href="https://s4.51cto.com/wyfs02/M02/9E/B0/wKioL1mUbEKhdUNnAAEtv24puww481.png" target="_blank"></a>
共享目錄的基本設定
mkdir /westos ##/下建立一個westos目錄
修改/westos/安全上下文,給/westos /mnt滿權限
<a href="https://s3.51cto.com/wyfs02/M02/9E/B0/wKioL1mUa5ywQhj3AADHlIBjPww246.png" target="_blank"></a>
開啟可寫功能
[DATA] 共享名稱
comment = 對共享目錄的描述
path = 共享目錄的絕對路徑
workgroup = WESTOS
<a href="https://s1.51cto.com/wyfs02/M00/9E/B0/wKioL1mUbOeQnbPKAAA7q60JmB8567.png" target="_blank"></a>
當共享目錄為使用者自建立目錄時
semanage fcontext -a -t samba_share_t '目錄名稱(/.*)?'
restorecon -RvvF 目錄名稱
<a href="https://s3.51cto.com/wyfs02/M00/9E/DF/wKioL1mYTp2TJD7MAACengCWdz8705.png" target="_blank"></a>
檢視使用者登陸
browseable = no ##隐藏共享的檔案,看不見但是可以使用
<a href="https://s1.51cto.com/wyfs02/M00/00/30/wKiom1mYUC3D-Xc0AAFBz5gw3bo659.png" target="_blank"></a>
<a href="https://s4.51cto.com/wyfs02/M01/00/30/wKiom1mYUFigKRB1AAD_2W4ddC0940.png" target="_blank"></a>
挂載
陌生使用者挂載
設定前
<a href="https://s2.51cto.com/wyfs02/M01/9E/E0/wKioL1mYUJHDmfD5AABsFfx8qtU185.png" target="_blank"></a>
設定後
<a href="https://s3.51cto.com/wyfs02/M01/00/30/wKiom1mYUMeTONcxAAA7q60JmB8681.png" target="_blank"></a>
<a href="https://s3.51cto.com/wyfs02/M00/9E/E0/wKioL1mYUMOAQVhCAAA6OrWGdOk980.png" target="_blank"></a>
<a href="https://s3.51cto.com/wyfs02/M01/00/30/wKiom1mYUMjg_uNnAAFRS7PpDG8196.png" target="_blank"></a>
設定自動挂載
<a href="https://s3.51cto.com/wyfs02/M02/00/30/wKiom1mYUPjTnrbGAACHenJt6K0936.png" target="_blank"></a>
<a href="https://s3.51cto.com/wyfs02/M02/9E/E0/wKioL1mYUPTzFOphAAFWYU9LU4U422.png" target="_blank"></a>
通路控制
valid usrs = lee #目前共享的有效使用者為lee
<a href="https://s2.51cto.com/wyfs02/M01/00/30/wKiom1mYU6DTSjU0AAA3gjJgH8M812.png" target="_blank"></a>
<a href="https://s1.51cto.com/wyfs02/M01/9E/E0/wKioL1mYU7OxwuNvAACMXDmtFwM554.png" target="_blank"></a>
<a href="https://s3.51cto.com/wyfs02/M00/00/30/wKiom1mYVE3yNtbDAACo4s5HZ74881.png" target="_blank"></a>
valid usrs = +(@)lee #目前共享的有效使用者組為lee
<a href="https://s2.51cto.com/wyfs02/M00/00/30/wKiom1mYVP6hVuUxAAA4g2DZpio771.png" target="_blank"></a>
<a href="https://s3.51cto.com/wyfs02/M01/00/30/wKiom1mYVQCigSIxAAC0ypi1R7k794.png" target="_blank"></a>
讀寫控制
writable = yes
<a href="https://s1.51cto.com/wyfs02/M02/9E/E0/wKioL1mYUz6xcnwvAABn9VcNZ6I165.png" target="_blank"></a>
<a href="https://s3.51cto.com/wyfs02/M00/00/30/wKiom1mYU2yTeju9AABLelzmynw437.png" target="_blank"></a>
<a href="https://s3.51cto.com/wyfs02/M02/9E/E0/wKioL1mYU2jQA-DiAAAy9sR-oIs153.png" target="_blank"></a>
設定指定使用者可寫
write list = student #可寫使用者
<a href="https://s2.51cto.com/wyfs02/M01/9E/E0/wKioL1mYVabT0nSHAABLMNx7iNo679.png" target="_blank"></a>
<a href="https://s2.51cto.com/wyfs02/M00/00/30/wKiom1mYVaux8laQAADtbdeqMJk884.png" target="_blank"></a>
write list = +lee #可寫使用者組
write list = @lee
usermod -G lee student
将student加入lee組中,這樣student也可寫了
admin users = lee #共享的超級使用者指定
<a href="https://s2.51cto.com/wyfs02/M02/00/30/wKiom1mYVVbDGAz4AACGG67F-GM611.png" target="_blank"></a>
smb多使用者挂載
6.smb多使用者挂載
在client上
vim /root/smbpasswd
username=student
password=student
<a href="https://s1.51cto.com/wyfs02/M01/00/30/wKiom1mYVc_iKRC5AAAbggFu8uc060.png" target="_blank"></a>
chmod 600 /root/smbpasswd
yum install cifs-utils -y
mount -o credentials=/root/smbpasswd,multiuser,sec=ntlmssp //172.25.254.225/CONFIG /mnt/
credentials=/root/smbpasswd 指定挂載時所用到的使用者檔案
multiuser 支援多使用者認證
sec=ntlmssp 認證方式為标準smb認證方式
ls /mnt
ls: cannot access /mnt: Permission denied #因為沒有作smb的認證是以無法通路smb共享
<a href="https://s4.51cto.com/wyfs02/M02/9E/E0/wKioL1mYVnWCBi5LAAB4W-qpkR4964.png" target="_blank"></a>
cifscreds add -u student 172.25.254.225
Password: ##smb使用者westos的密碼
<a href="https://s4.51cto.com/wyfs02/M00/9E/E0/wKioL1mYVoSQXcC9AABKTP6MBPQ739.png" target="_blank"></a>
本文轉自 happy_newbie 51CTO部落格,原文連結:http://blog.51cto.com/12971521/1957758,如需轉載請自行聯系原作者