林科佑
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • 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

      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.
      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
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • 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 Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • 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

    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.
    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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: 1101_lsa --- # 鎖定使用者 in Linux - 有很多種讓使用者體感上覺得自己被鎖定的方式 - 但 linux 中,鎖定的方式卻有不同的用意 - 只鎖定使用者的密碼 - 直接鎖定使用者 :::success **前情提要** - 查看此主機中,有哪些使用者帳號及其資訊 - /etc/passwd - 雖然 `/etc/passwd` 有一個密碼欄位,但實際上存密碼的地方 - /etc/shadow ::: ## 密碼欄位 ### `/etc/passwd` - `x` - 密碼存在 /etc/shadow 裡 - 會自動幫你到 /etc/shadow 比對密碼 :::info **linux 找密碼的順序** - 先找 `/etc/passwd` 如果密碼欄位是 `x`,則到 `/etc/shadow` 找密碼 ::: ### `/etc/shadow` - `{$加密演算法$salt$密文}` - 這個使用者加密過後的密碼 :::info **salt** - Why we need that ? - 彩虹表的鍋 :::spoiler 小故事 - 加密技術雖然越來越強,密碼被暴力破解的難度提升,但道高一尺魔高一丈,有一張神奇的表,叫做彩虹表,簡單來說就是可以幫你找出雜湊前的密碼長甚麼樣子,而且速度還比暴力破解快 ::: - 在密碼中加入 salt (鹽巴) 讓原本的密碼走味,這樣別人就猜不到這個你原先的密碼是甚麼 - 在密碼雜湊之前,先在密碼中特定位置塞入隨機字串再進行雜湊。 - 增加暴力破解的難度。 - 就算不幸被破解,破解者得到的字串也不是你原先的密碼 (而是加過鹽的密碼) :::warning - 原先密碼 - abcdefg - 加鹽 (123) - abcdefg**123** - ab**1**cd**2**ef**3**g ::: ::: - ` ` - 沒有密碼 - `passwd` 可以直接新增密碼 - `!` 及 `!!` - 此帳號的密碼被鎖定 - 原本有密碼,但被 lock 住 - `*` - 此帳號無預設密碼 - 一開始建立此帳號時,就沒有密碼 :::info **小 demo** - `sudo adduser ttt` - 不打密碼 - `sudo adduser --disabled-password ttt1` - `sudo cat /etc/shadow` ::: :::danger **不能用密碼登入 不代表那個使用者不能用** - `!` `*` 只是代表這個使用者不能透過 password authentication 的方式登入系統 - 用 **key-based authentication** 跟 **switching user** 依然可以讓這個使用者登入系統 ::: ## Demo :::success **首先先建一個新的使用者** - `sudo adduser test` - `cat /etc/passwd` - `sudo cat /etc/shadow` ::: - `sudo passwd -l test` - in `test` - `passwd -S` 看狀態 - ![](https://i.imgur.com/rjakAax.png =450x) - L : 密碼被 Lock 住了 - `sudo cat /etc/shadow` - `test` 的密碼欄位開頭被加入 `!` - `passwd test` 沒辦法改密碼 - ![](https://i.imgur.com/Tl38iju.png =450x) - 但是在鎖住的過程還是可以用以下兩種方式,登入系統 - key-base 認證遠端連線 - `ssh-copy-id /home/keke/.ssh/id_rsa.pub test@127.0.0.1` - `ssh -v test@127.0.0.1` - root 切換使用者 - `sudo su - test` - `sudo passwd -u test` - in `test` - `passwd -S` 看狀態 - ![](https://i.imgur.com/REknRKU.png =450x) - P : 有可用的 Password - `passwd test` 可以改密碼了 - `usermod` 也可以達到一樣的效果 - `usermod` 修改使用者帳號的各項資訊 - `sudo usermod -L test` - `sudo usermod -U test` ### 如何把這個帳號鎖定的滴水不漏 - 將該帳號的 bash 設成 `/sbin/nologin` - 會友善地告訴你不能登入喔,然後狠狠的把你拒之門外 - `sudo usermod -s /sbin/nologin test` - 使用 **key-base 認證** 或 **切換使用者** 都無法登入這個帳號 - `sudo usermod -s /bin/bash test` - 直接讓這個帳號過期 - `chage` 主要用來更改使用者帳號或密碼的期限 - `sudo chage -l test` - 看一下狀態 - `sudo chage -E 0 test` - `-E {天數}` : 設定帳號從 1970-01-01 開始算 {天數} 後過期 - 天數為 0 則立即過期,-1 則永遠不會過期 - 使用 **key-base 認證** 或 **切換使用者** 都無法登入這個帳號 - `sudo chage -E -1 test` <!-- :::info **參考資料** - https://stackoverflow.com/questions/24105498/what-do-and-mean-in-the-password-section-in-etc-shadow - https://linuxize.com/post/etc-shadow-file/ - https://dywang.csie.cyut.edu.tw/dywang/linuxSystem/node58.html - https://blog.gtwang.org/linux/linux-passwd-command-examples/ - https://zhuanlan.zhihu.com/p/71834401 ::: -->

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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