CentOS 7.2 安裝配置Samba伺服器

來源:互聯網
上載者:User

標籤:安裝   pac   stand   user   question   samba伺服器   pack   rect   儲存   

1背景

轉Linux剛剛1年,vim操作還不能應對工程代碼,之前一直都是Gnome案頭 + Clion 作開發環境,無奈在伺服器上沒有這樣的環境,

看同事是(Windows)Source Insight + WinSCP + Linux 開發,來回同步檔案有點麻煩,所以想嘗試搭個Samba伺服器做共用檔案。

不過希望以後還是要轉到vim上來。

 

2環境

CentOS系統

[[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 

 

Samba伺服器

[[email protected] ~]# rpm -qi sambaName        : sambaEpoch       : 0Version     : 4.4.4Release     : 9.el7Architecture: x86_64Install Date: Sun 18 Dec 2016 11:59:56 PM CSTGroup       : System Environment/DaemonsSize        : 1869290License     : GPLv3+ and LGPLv3+Signature   : RSA/SHA256, Mon 21 Nov 2016 04:38:30 AM CST, Key ID 24c6a8a7f4a80eb5Source RPM  : samba-4.4.4-9.el7.src.rpmBuild Date  : Mon 07 Nov 2016 06:31:03 PM CSTBuild Host  : worker1.bsys.centos.orgRelocations : (not relocatable)Packager    : CentOS BuildSystem <http://bugs.centos.org>Vendor      : CentOSURL         : http://www.samba.org/Summary     : Server and Client software to interoperate with Windows machinesDescription :Samba is the standard Windows interoperability suite of programs for Linux andUnix.
 3安裝
[[email protected] ~]# yum -y install samba samba-client
 4配置

進入samba配置目錄

[[email protected] ~]# cd /etc/samba/

 

備份smb.conf

[[email protected] samba]# mv smb.conf smb.conf.origin

 

建立smb.conf

[[email protected] samba]# vim smb.conf

內容如下,儲存並退出

[global]        workgroup = WORKGROUP        server string = Ted Samba Server %v        netbios name = TedSamba        security = user        map to guest = Bad User        passdb backend = tdbsam[FileShare]        comment = share some files        path = /smb/fileshare        public = yes        writeable = yes
create mask = 0644
directory mask = 0755[WebDev] comment = project development directory path = /smb/webdev valid users = ted write list = ted printable = no create mask = 0644 directory mask = 0755

 注釋:

workgroup 項應與 Windows 主機保持一致,這裡是WORKGROUP

security、map to guest項設定為允許匿名使用者存取

再下面有兩個section,實際為兩個目錄,section名就是目錄名(映射到Windows上可以看見)。

第一個目錄名是FileShare,匿名、公開、可寫

第二個目錄嗎是WebDev,限定ted使用者訪問

預設檔案屬性644/755(不然的話,Windows上在這個目錄下建立的檔案會有“可執行”屬性)

 

建立使用者

[[email protected] samba]# groupadd co3[[email protected] samba]# useradd ted -g co3 -s /sbin/nologin[[email protected] samba]# smbpasswd -a tedNew SMB password:Retype new SMB password:Added user ted.[[email protected] samba]# 

注意這裡smbpasswd將使用系統使用者。設定密碼為1

 

建立共用目錄

[[email protected] samba]# mkdir -p /smb/{fileshare,webdev}[[email protected] samba]# chown nobody:nobody /smb/fileshare/[[email protected] samba]# chown ted:co3 /smb/webdev/

注意設定屬性,不然訪問不了。

 

啟動Samba服務,設定開機啟動

[[email protected] samba]# systemctl start smb[[email protected] samba]# systemctl enable smbCreated symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.[[email protected] samba]# 

 

開放連接埠

[[email protected] samba]# firewall-cmd --permanent --add-port=139/tcpsuccess[[email protected] samba]# firewall-cmd --permanent --add-port=445/tcpsuccess
[[email protected] samba]# systemctl restart firewalld
[[email protected] samba]# 

或者直接把防火牆關了也行。

 5使用 Linux訪問

可以使用testparm測試samba配置是否正確

[[email protected] samba]# testparm Load smb config files from /etc/samba/smb.confrlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)Processing section "[FileShare]"Processing section "[WebDev]"Loaded services file OK.Server role: ROLE_STANDALONEPress enter to see a dump of your service definitions# Global parameters[global]    netbios name = TEDSAMBA    server string = Ted Samba Server %v    map to guest = Bad User    security = USER    idmap config * : backend = tdb[FileShare]    comment = share some files    path = /smb/fileshare    guest ok = Yes    read only = No[WebDev]    comment = project development directory    path = /smb/webdev    create mask = 0644

valid users = ted write list = ted[[email protected] samba]#

 

root使用者的話,不用密碼可直接查看samba伺服器情況

[[email protected] samba]# smbclient -L localhost Enter root‘s password: Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.4.4]    Sharename       Type      Comment    ---------       ----      -------    FileShare       Disk      share some files    WebDev          Disk      project development directory    IPC$            IPC       IPC Service (Ted Samba Server 4.4.4)Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.4.4]    Server               Comment    ---------            -------    Workgroup            Master    ---------            -------[[email protected] samba]# 

 

Windows訪問1)在Windwos資源管理員訪問

訪問路徑裡填上: \\${Samba伺服器的IP} ,然後斷行符號,可以看見共用的目錄。

 

FileShare是可以匿名訪問的,可以訪問、建立、刪除檔案。

這裡拖進去一個txt檔案,可以在Linux上看見該檔案。

 

2)映射網路磁碟機

右邊的WebDev目錄是要求輸入密碼訪問的

 

這裡示範一下映射該目錄為網路磁碟機。

“案頭” 按右鍵“此電腦”,選擇“映射網路磁碟機”

在檔案夾位置填寫該共用檔案的網路路徑,這裡是\\192.168.118.132\WebDev

勾選“使用其他憑據串連”,點“完成”。

 

 

填寫使用者密碼

 

 在我的電腦可以看見該網路磁碟機(Y)

 

這裡可以放源碼工程,然後用Windows下的IDE開啟、編輯,再在Linux編譯、運行。

 

enjoy it~

以後有需求再補充Linux掛載samba共用目錄、許可權配置等等。

 

6參考文獻

Linux Samba伺服器配置

CentOS7安裝配置SAMBA伺服器

CentOS7下Samba的安裝與配置

配置samba伺服器,中加入了security=share,但是testparm輸出的資訊裡沒有這一條,客戶機也無法訪問

smb伺服器目錄和檔案使用權限設定

CentOS 7.2 安裝配置Samba伺服器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.