這兩天業務需求搭了一台服務器。要求samba共享文件。
葡萄美酒月光杯的前戲就省了,我們直接上干貨。
1、yum方式安裝samba
yum -y install samba
2、將/etc/samba/smb.conf文件備份一個(個人習慣,不備份也是可以的)
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
3、修改對應文件
[root@ceshi01-10 samba]# cat smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
map to guest = bad user #在centos7之后都要加這一行了
hosts allow=192.168.10.21 192.168.10.22 #只允許某些ip訪問這台samba服務器;多個ip之間用空格隔開即可;如果允許某一個網段的話,可以這樣:192.168.10.0/24
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
[myshare] #這是samba共享文件的一個名詞;自己可以隨便起個123都行,但最好起得有點代表性
comment = yang share #這個comment后面的文字是對這個samba的解釋
path = /data #path是要分享的路徑,記住,這路徑一定要給到合適權限,不然訪問會出錯的。
writable = yes #決定訪問的用戶能否寫入文件
guest ok = yes #決定訪客用戶能否訪問
browseable = yes #出於安全考慮,有時會讓客戶端無法看到某個共享目錄,這樣只有管理員或者一些重要人士知道Samba服務器上有這樣一個目錄,而其它人員並不知道這個目錄。
[root@ceshi01-10 samba]#
4、要記得服務器的防火牆一定要關閉;或者開通防火牆權限才行。
5、服務器端安裝samba客戶端
yum install cifs-utils
mount -t cifs -o username="root",password="" //ip/共享文件夾名字 /掛載點
列如:
mount -t cifs -o username="root",password="p" //192.168.10.20/myshare /mnt
[root@ceshi02-10 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 7.9G 9.2G 47% /
devtmpfs 898M 0 898M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 9.6M 901M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda1 1014M 146M 869M 15% /boot
tmpfs 182M 0 182M 0% /run/user/0
//192.168.10.20/myshare 17G 1.4G 16G 8% /mnt
[root@ceshi02-10 ~]# vf mnt
6、如果是windows訪問的話
直接windows+R的彈窗輸入\\192.168.10.20就可以了。