Windows 與 Linux (CentOS7) 之間的文件共享
折騰了好幾天,終於搞定了,之前還以為直接拖進去虛擬機里就行,但是一直說解壓錯誤,后面看文件大小,發現才只有原來的十分之一大,所以肯定是傳輸的過程中出錯了。后面搜索解決方案,不能直接復制粘貼,搜索發現有以下三種方式:
- 安裝 samba;
- 設置 VMware 共享目錄;
- window 中安裝 FTP 或 SSH 軟件。
我主要講的是第一種方法,第二種我自己試了一下,沒成功,接下來正式開始安裝!
一、安裝 Samba
檢查samba是否已經安裝
[root@localhost ~]# rpm -qa | grep samba
samba-common-4.9.1-6.el7.noarch
samba-client-4.9.1-6.el7.x86_64
samba-4.9.1-6.el7.x86_64
samba-client-libs-4.9.1-6.el7.x86_64
samba-common-tools-4.9.1-6.el7.x86_64
samba-common-libs-4.9.1-6.el7.x86_64
samba-libs-4.9.1-6.el7.x86_64
注意:我是已經安裝好了的,所以才會有如上的顯示,如果未安裝,則沒有上面的顯示。一般安裝 CentOS 7 就會默認帶有 Samba 的安裝包,所以只需要執行一下命令:
yum -y install samba samba-client samba-common
這個命令既安裝了 Samba 也安裝了客戶端 samba-client,所以再次檢查安裝結果就會跟我的一樣了,有差別的只有版本號不同。
[root@localhost ~]# rpm -qa | grep samba
samba-common-4.9.1-6.el7.noarch
samba-client-4.9.1-6.el7.x86_64
samba-4.9.1-6.el7.x86_64
samba-client-libs-4.9.1-6.el7.x86_64
samba-common-tools-4.9.1-6.el7.x86_64
samba-common-libs-4.9.1-6.el7.x86_64
samba-libs-4.9.1-6.el7.x86_64
二、配置 samba
1.關閉 SELINUX
[root@localhost ~]# vi /etc/sysconfig/selinux
如下所示:
修改下邊紅字部分
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
3.關閉防火牆
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
4.重啟計算機
[root@localhost ~]# shutdown -r now
5.創建共享目錄
[root@localhost home]# mkdir -p /home/share/software
6.創建共享用戶組
[root@localhost home]# groupadd share
7.創建共享用戶
[root@localhost home]# useradd -g share -s /sbin/nologin share
8.設置共享目錄權限
[root@localhost home]# chown -R share:share /home/share/software
9.修改共享用戶密碼
[root@localhost home]# /bin/smbpasswd -a share
New SMB password:
Retype new SMB password:
Added user share.
10.修改 samba 配置文件
[root@localhost share]# vi /etc/samba/smb.conf
11.配置文件說明如下
[global] #全局變量
workgroup = WORKGROUP #工作組
security = user #登陸才可訪問共享
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[software] #顯示的共享目錄名
path = /home/share/software #共享目錄路徑
comment = Software Directories #共享目錄描述
writeable = Yes #共享目錄可寫入
write list = share #有寫入權限的用戶
valid users = share #共享目錄的用戶
browseable = Yes #是否可瀏覽文件
read only = No #是否只讀
inherit acls = No
注意:自己寫的時候可以復制上面的 [software] 里的內容,但是必須要把 # 號后面的內容刪除掉,這里是為了跟你說明是用來干什么的,實際文件里不要帶這些注釋說明,否則會報錯!我就是一開始不知道,導致出錯的!
12.修改完配置文件后,需要先運行一下(這個是檢查 smb.conf 有沒有錯誤的命令):
[root@localhost home]# testparm
看有沒有什么錯誤,我之前報的如下的錯誤:
錯誤一:
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
見到如上的錯誤,就得繼續以下的修改:
[root@localhost ~]# vim /etc/security/limits.conf
root - nofile 16384
root指root用戶 如果想都所有用戶生效,把root替換為 * 即可!我是設置的 * 下面是配置文件內容
\#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
#
#Each line describes a limit for a user in the form:
#
#
#
#Where:
#can be:
# - a user name
# - a group name, with @group syntax
# - the wildcard *, for default entry
# - the wildcard %, can be also used with %group syntax,
# for maxlogin limit
* - nofile 16384
#
#can have the two values:
# - "soft" for enforcing the soft limits
# - "hard" for enforcing hard limits
#
#- can be one of the following:
# - core - limits the core file size (KB)
# - data - max data size (KB)
# - fsize - maximum filesize (KB)
# - memlock - max locked-in-memory address space (KB)
錯誤二:
set_variable_helper(Yes #共享目錄可寫入): value is not boolean! Error loading services.
這個錯誤就是我之前所說的,沒有刪掉 # 號以及 # 后面的注釋的內容,當然這里不要把開頭的那幾行帶 # 號的內容刪掉了!
13.給共享目錄賦予各種權限 (這里設置好了 就沒有權限問題了!)
[root@localhost ~]# chmod 777 /etc/samba
[root@localhost ~]# chmon 777 /etc/samba
14.啟動samba服務
[root@localhost share]# systemctl start smb
15.設置samba服務開機自啟動
[root@localhost share]# systemctl enable smb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
引自:https://blog.51cto.com/lzlutao/2367732
本文在此基礎上稍作修改!
