📂
JackyChen的精神時光屋
  • About
  • iPlayground
    • iPlayground 2020
      • iPlayground submit 2020
    • iPlayground 2019
      • Untitled
      • iPlayground submit 2019
  • WWDC
    • 2020 WWDC
    • 2019 WWDC
    • 2018 WWDC
      • What's New in Testing
      • BusinessChat
    • 2016 WWDC
      • What's New in the Apple Push Notification Service
  • AR/VR
    • ARKit plugin at Unity
    • ARKit
    • AR/VR 實習作品分享
    • Google Blocks
  • CI/CD
    • Continous Integretion for Unity
    • 拯救地球大作戰-自動化設定注意事項
    • Provisioning Profile 自動化更新
    • Make ipa file with personal team of code sign
    • Xcode11 版號問題
  • Test
    • Cucumberish
    • XCUITest
    • Design Patterns in XCUITest
    • Unit Test
  • User Interface
    • IBDesignable 和 IBInspectable
    • iOS 使用貝塞爾曲線繪製路徑
    • UIStatusBarStyle
    • iOS Devices Specification
    • Vector Image
    • Launch Screen
    • Haptic Feedback
    • Good Works for Storyboard
    • Cell 展開收合效果
    • ScrollView
    • Swift lazy
    • Lottie
  • Foundation
    • Adding a Custom Font to Your App
    • WKWebView how to work with javascript
    • Global Central Dispatch
    • HealthKit
    • Error Handling
    • Debug with LLDB
    • Application Lifecycle
    • Swift Codable
    • Push Notifications
    • AVFoudation
  • Others
    • C語言指標概念
    • UnsafePointer(Swift)
    • iOS News Reference
    • Blender
    • Free Web Server
    • Firebase
    • Firebase migration
    • GraphQL
    • Ruby
    • zsh command line
    • visudo
  • Security
    • 課程:App資安規劃與實作
    • KeyChain
    • iOS反組譯程序
    • Arxan
  • Git
    • Git
    • xcodeproj 合併衝突
    • Pull Request
  • Machine Learning
    • CoreML
    • Vision
    • Turi Create
  • 待分類
    • ABI Stability and More
    • Mirror
    • Carthage
    • SwiftUI
    • MVVM
    • OpenSSL
    • USDZ Convert
    • Nexus repository and gitlfs
Powered by GitBook
On this page
  • /etc/sudoers sudo 簡介
  • 修改 /etc/sudoers 的方法
  • 進階設定方式
  • App 開發情境的應用

Was this helpful?

  1. Others

visudo

/etc/sudoers sudo 簡介

sudo 的執行則僅需要自己的密碼, 甚至可以設定不需要密碼即可執行 sudo。sudo 可以讓你以其他用 戶的身份執行指令 (通常是使用 root 的身份來執行指令),僅有規範到 /etc/sudoers 內的用戶才能夠執 行 sudo 這個指令。 Mac 系統預設僅有管理者權限的人可以執行 sudo。

修改 /etc/sudoers 的方法

使用 visudo 去修改 /etc/sudoers ,讓該帳號能夠使用全部或部分的 root 指令功能。因為 /etc/sudoers 是有設定語法的,如果設定錯誤那會造成無法使用 sudo 指令的不良後果。因此使用 visudo 去修改, 在結束離開修改畫面時,系統會去檢驗 /etc/sudoers 的語法,避免錯誤發生。

root@study ~]# visudo
....(前面省略)....
root ALL=(ALL) ALL
i9200800 ALL=(ALL) ALL <==這一行是你要新增的! ....(底下省略)....

上面這一行的四個元件意義是:

  • 『使用者帳號』:系統的哪個帳號可以使用 sudo 這個指令的意思。

  • 『登入者的來源主機名稱』:當這個帳號由哪部主機連線到本 Linux 主機,意思是這個帳號可能

    是由哪一部網路主機連線過來的, 這個設定值可以指定用戶端電腦(信任的來源的意思)。預設值

    root 可來自任何一部網路主機。

  • 『(可切換的身份)』:這個帳號可以切換成什麼身份來下達後續的指令,預設 root 可以切換成任

    何人。

  • 『可下達的指令』:可用該身份下達什麼指令?這個指令請務必使用絕對路徑撰寫。 預設 root 可

    以切換任何身份且進行任何指令之意。

進階設定方式

無需密碼,就可以執行 sudo 的方法

i9200800  ALL=(ALL)  NOPASSWD: ALL

限制的可執行的指令

i9200800 ALL=(ALL) /usr/bin/xcode-select

使用正規表示式限制指令的部份參數不可使用 以下設定為可以執行『 passwd 任意字元』,但是『 passwd 』與『 passwd root 』這兩個指令例外

i9200800 ALL=(ALL) /usr/bin/passwd [A-Za-z]*, !/usr/bin/passwd, !/usr/bin/passwd root

App 開發情境的應用

App 開發人員,為了因應每年升級的預做準備,需要安裝多個 Xcode 的版本進行測試。

Xcode 版本的切換,需要有管理者權限才可執行,透過設定 sudo 指令的權限,可讓開發人員不需具備 管理者權限也可以切換不同的 Xcode 版本。

使用「終端機」,輸入 sudo xcode-select -s /Applications/Xcode11.1.app 可切換不同的 Xcode 版本

因 sudo 命令的限制,也不需擔心開發人員擁有過多權限,當使用者輸入未被授權的指令,即出現以下 提示訊息:

i9200800de-iMac:~ $ sudo ls
Password:
Sorry, user i9200800 is not allowed to execute '/bin/ls' as root on i9200800de- iMac.local.
Previouszsh command lineNext課程:App資安規劃與實作

Last updated 5 years ago

Was this helpful?