你想不到吧
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: LDAP架設 tags: Open distro description: View the slide with "Slide Mode". --- # LDAP架設 <!-- Put the link to this slide here so people can follow --> ## 目標 1. 要裝哪些套件 # :moyai: 2. 如何儲存資料 -> 部門員工權限 # :moyai: 3. 記下那些結構 4. schema是什麼 5. 如何查詢 6. 讓用戶端使用 LDAP Server 作為帳號驗證來源之一 7. [鳥哥 - LDAP]( http://dic.vbird.tw/linux_server/unit07.php ) 7.1: 身份識別與檔案系統間的關係 7.2: LDAP 簡介 7.3: LDAP 的實際設定流程 7.4: LDAP 資料庫簡易管理 (新增/刪除/修改用戶參數) 7.5: 分享檔案系統的 NFS 伺服器 ## 7.1: 身份識別與檔案系統間的關係 - 總結說明身份識別與檔案系統間的關係就是:在一組或一間伺服器機房內,所有的伺服器均需要使用同一組帳號與密碼來登入, 並取得相同家目錄時,就需要這樣的設備需求。 #### 情境 - 在崑山資傳系操作電腦教室的電腦時,所有的電腦均可以使用你的學號登入,並且可以取得你的個人桌面與額外的三個檔案系統。 因此在資傳系上課時,你可以在五間電腦教室的任何一間,使用相同的帳密登入,並可取得前一次上課的桌面與工作家目錄。所以如果對當前的座位不滿意, 可以立刻換座位,也不會影響到你的正常操作。 #### 再次強調該功能就得要有兩個元件: 1. 使用身份識別功能:就是 ID 認證的服務。常見的服務有: NIS, LDAP, AD(windows), Kerboros... 2. 使用者家目錄的取得:就是個人檔案資料。常見的服務有: NFS, SMB(網芳), AD(windows)... - linux來說,建議以<font color=blue> LDAP 搭配 NFS</font> 來進行整體系統架構的設定 ## 7.2: LDAP 簡介 - LDAP 全名: Lightweight Directory Access Protocol - 主要的功能在於『目錄服務 (directory service)』的提供! - 在軟體工程中,一個目錄是指一組名字和值的對映 - 簡單的說,就是你可以<font color=blue>提供一個查詢的資料對應的內容</font>,舉例來說,你可以提供一個『帳號名稱』,而在這個帳號名稱底下給予對應了密碼、UID、GID、真實姓名等資訊, 若用戶端使用帳號名稱來查詢目錄服務,則可以得到該帳號的密碼、UID等等資訊就是了 - <font color=red>LDAP 目錄結構組成</font> :::success <font color=red>DN</font>,Distinguished Name:識別名稱,LDAP 中一筆記錄的位置 RDN,Relative Distinguished Name:相對識別名稱,CN 及 CN 的值。例如:cn=deyu 獨一無二的屬性。 <font color=red>CN</font>,Common Name/uid:顯示名稱,一筆 LDAP 記錄的名字/ID OU,Organizational Unit:組織,一筆 LDAP 記錄所屬組織 <font color=red>DC</font>,Domain Componet:網域元件,一筆 LDAP 記錄所屬區域 ::: ### LDAP 的組成 >- 基本上,你就將 LDAP 想成是一個目錄,而每個目錄都有個目錄名稱,然後根據不同需求,可以給予更多的目錄節點 >- 單純以節點的角度來看,以一個公司名稱為『 example.com 』的位置來說,該公司的相關部門位置節點有點像這樣 >- 如上所示,公司底下有兩個部門 (organization unit),一個是伺服器部門 (Servers) 一個是人資部門 (People) ,其中人資部門底下管理著員工證號 (Person, udid), 大概就是這樣一層一層的分配下來~而每一個節點底下可以搭配不同的資料給予特別的任務就是了。 >- 因此,只要找尋不同的 location 即可取得各自部門的人資訊息 ![](https://i.imgur.com/as0Pc1m.png) - 每一筆資料則透過<font color=blue>判別名稱 (distinguished name, DN)</font> 來提示定義 - 每一個組織均需要定義最頂層的判別名稱,就被稱為<font color=blue> baseDN</font>,這也是整個 LDAP 系統最先要設定的項目。 例如上圖的『 dc=exmpale,dc=com 』以及底下的『 dc=company,dc=com 』都是所謂的 baseDN !你可以猜測在組織 (Organization) 那一層的名稱, 就是 baseDN 的意思了 - 每一筆查詢資料稱為 DN (Distinguished Name),而 <font color=blue>DN 就是呼叫出目錄節點的位置所在</font>。例如上面提到的 baseDN 就是一例。 他的展現方式就是『 dc=exmaple,dc=com 』,從小範圍寫起直到最頂層 (dc=com) 為止。 事實上,DN 的展示方式其實有點像 DNS,不過需要使用 dc, ou, cn 等來進行名稱的指定。<font color=blue>dc (domain component) 一般用在公司或最頂層 DN 的設定, ou (organization unit) 一般用在大部門的設定上</font>, cn (common name) 一般用在非上述兩個用途的其他應用上 - 每個 baseDN 底下還有附屬組織單位,那就是 organization unit 的概念。例如人事部門可以使用類似: <font color=blue>『 dn: ou=People,dc=example,dc=com 』</font>之類的方式來命名。而該 DN 底下就會有多種屬性定義!這些屬性定義就牽涉到每一個 LDAP 的用途為何。 >[name=昱齊] 先用dc來表達公司的FQDN,再用ou來指公司底下的組織單位,dc+ou也就是一種dn - 因為 LDAP 僅是一個『目錄服務』的提供者,但<font color=blue>這些目錄底下資料的定義使用的功能為何,就是透過預先定義的綱要檔 (Schema) 來定義</font>。 舉例來說, Linux 與 Windows 的帳號所需要的項目並不相同,因此使用 LDAP 作為 Linux 的帳號認證來源時,就得要使用 LDAP 提供的 Linux 帳號所需綱要檔 (schema) ### <font color=red>LDAP 的架設流程簡介</font> 如果確定要架設 LDAP 作為你的身份驗證來源,那麼你得要事先規劃好這部 LDAP 所提供的 baseDN、相關的管理者密碼、相關的帳號 UID 起始號碼、 相關的使用者家目錄 (最好不要跟系統預設的 /home 相同位置,否則容易造成本機帳號與網路帳號衝突的狀況)等等。至於一般的架設流程大概是這樣的: :::success 1. 安裝好 LDAP 伺服器軟體,並且提供登入 LDAP 功能的 <font color="#C98E85"> RootDN 密碼</font> 1. 載入 LDAP 所需要的環境設定參數檔 1. 啟動 LDAP 服務,並觀察 LDAP 服務的埠口,以啟用防火牆放行的功能 1. 預先指定好自己公司即將使用的 baseDN 環境 (最好與 DNS 系統相同即可),同時規劃好即將要使用的用戶端作業系統有哪些 1. 開始載入基本的 <font color="#C98E85">baseDN</font> 功能 1. 開始載入用戶端作業系統所需要的綱要檔 (schema) 1. 嘗試取得用戶端所需要的帳號參數範例檔,變轉為 LDAP 所需要的格式 <font color="#C98E85">(LDAP Data Interchange Format, LDIF)</font>,然後載入到 LDAP 伺服器內 1. 若需要加密環境,請前往 /etc/pki/tls/certs 目錄下進行所需要的 key 建制 ::: ### LDAP 的實際設定流程 為了避免 Server/client 之間名稱解析產生的連線延遲,因此 IP 對應主機名稱最好還是寫入 /etc/hosts 較佳 ```htmlmixed= [root@localhost ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.254.xxx pcxxx.dic.ksu pcxxx 192.168.254.254 pc254.dic.ksu pc254 10.255.xxx.254 server.lanxxx.dic.ksu server <==這個項目 10.255.xxx.1 client.lanxxx.dic.ksu client <==這個項目 ``` #### 1. 安裝 LDAP 相關軟體、啟動 slapd 服務以及了解 LDIF 格式與匯入 LDIF 檔案 要能夠執行 LDAP server 至少也需要 openldap-servers, openldap-clients, openldap 等軟體才行~不過,後續我們會用到 Linux 帳號轉成 LDAP 帳號的機制, 那就得要額外安裝 unix 帳號轉 ldap 帳號的轉換腳本 migrationtools 這個軟體才行! ##### 任務 1. 安裝所需要的四個軟體 1. 啟動、開機啟動 slapd 服務,同時觀察一下該服務! 1. 觀察埠口,是否有 port 389 的產生?,透過`netstat` 1. 觀察防火牆,僅針對內部網路 (10.xxx) 來說,是否還需要額外放行防火牆規則? :::spoiler --- ``` [root@localhost ~]# ldapadd -x -W -D "${RootDN}" -f LDIf_filename [root@localhost ~]# ldapadd -x -W -D "cn=Manager,dc=dic,dc=ksu" -f /root/ldap/base.ldif ``` ![](https://i.imgur.com/L1rUo5B.png) 這裡說明一下 LDAP 主要的簡稱含義: DIT(Directory Information Tree;目錄資訊樹) o - organization (組織) ou - organization unit (組織單位-部門) c - country Name (國家) dc - domain Component (域名) sn - suer name (真實姓名) cn - common name (使用者名稱) dn - Distinguish Name (識別名稱) > 修改slapd.conf suffix "dc=mp,dc=nttu,dc=edu,dc=tw" rootdn "cn=username,dc=mp,dc=nttu,dc=edu,dc=tw" 表示法 表示出towns在LDAP的唯一識別名稱(DN) cn=username, cn=cy, cn=unit, cn=company, dc=mp,dc=nttu,dc=edu,dc=tw LDAP的識別方式與DNS類似,<font color=blue>由小排大</font> ## 安裝 在CentOS7上安裝OpenLDAP Server 一、 安裝套件 1. 安裝 openLDAP 套件 # yum -y install openldap* 2. 安裝 migrationtools 工具 # yum install migrationtools 二、 清除範例資料並新增目錄與設定檔 1. 清除範例資料 # rm -rvf /etc/openldap/slapd.d 2. 建立目錄 # mkdir /etc/openldap/slapd.d 3. 複製設定的範例檔 # cp /usr/share/openldap-servers/slapd.ldif /etc/openldap/slapd.conf 三、 設定管理密碼並查看 1. 切換到openldap # cd /etc/openldap 2. 設定密碼並輸出到文字檔,方便以 tail 查看 # slappasswd > password.txt 3. 查看{SSHA}密碼並複製到記事本備用 # tail password.txt 四、 編輯設定檔 1. 編輯 slapd.conf 主要控制的設定檔 # nano /etc/openldap/slapd.conf 把所有的dc=my-domain,dc=com改成dc=mp,dc=nttu,dc=edu,dc=tw 然後結尾補上 olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxxxx (從剛剛記事本那邊貼過來) [雜介紹](http://weng-weiling.blogspot.com/2017/05/ldap-server.html) --- ### [不廢話直上版](http://linux.onlinedoc.tw/2016/05/centos7rhel7-ldap-server.html) :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully