圖形介面如何暫時取得最高權限(sudo) - Linux

By Barb Cronin
at 2019-04-12T20:46
at 2019-04-12T20:46
Table of Contents
※ 引述《stonys (蝶戀影)》之銘言:
: 大家好
: 小弟雖然會sudo指令操作
: 也會一點VI編輯器操作
: 不過有時候想寫一些程式(php之類)的話,還是覺得用GUI的編輯器比較方便
: 可是常常要存檔時會遇到權限問題(登入帳號已經是管理員了)
: 此時只好先存在一般路徑,再用終端機下sudo cp的指令複製過去
: 想請問一下如果在圖形介面裡,如何取得sudo操作權限呢?
: 目前常用的的redhat Enterprise 7 & Ubuntu 18.04
: 謝謝!
因為之前查 wine 相關的 FAQ 瞄到:
https://wiki.winehq.org/FAQ#Is_Wine_malware-compatible.3F
所以就剛好有了
用其他使用者權限(非 root)跑跑看 wine
的想法,雖然不知道效果如何
於是參考原文底下推文的討論,搭配 arch wiki 參考整理一些使用上的心得
首先剛開始在查時常看到:
: → : 在你的指令前加上gksu
類似的方法,但後來發現一些比較新的發行版似乎已經不用這個指令了
所以就使用了需要安裝 polkit 套件(有些發行版已經裝好了)的 pkexec 指令
大概步驟如下:
1. 在自己帳號的桌面開終端機輸入:
~$ xhost +
應該會出現: access control disabled, clients can connect from any host 的訊息
2. 確認要用的程式被 polkit 允許
參考: https://wiki.archlinux.org/index.php/Polkit#Actions
到 /usr/share/polkit-1/ 底下的 actions 或 rules.d 確認
自己要用的指令有沒有被 polkit 允許
沒有的話可以參考 wiki 裡面給的格式修改增加你要的指令
3. 確認自己的 $DISPLAY 變數
~$ echo $DISPLAY
應該會顯示等資訊
> ---
:0
> ---
4. pkexec 執行程式
就
pkexec --user <切過去的帳號> env DISPLAY=:0 <你要執行的指令>
例如想要用 gedit 編輯由 www-data 持有的 /var/www/html/index.html
就可以:
~$ pkexec --user www-data env DISPLAY=:0 gedit /var/www/html/index.html
或是我想要用 winewine 這個使用者來跑 wine 裡面的 IE
~$ pkexec --user winewine env DISPLAY=:0 wine iexplore
即可
==
至於相關環境變數要怎麼設定
目前想法是就一直加 env 變數=變數內容 像是:
~$ pkexec --user winewine env DISPLAY=:0 env WINEARCH=win32 wine winecfg
則是還不太確定,之後有需要再測試看看或看有沒有相關資料討論
也或許有其他比較easy的方法
但總之在這邊分享自己經驗以供參考
--
Paramore - Franklin
And when we get home, I know we won't be home at all
This place we live, it is not where we belong
And I miss who we were in the town that we could call our own
Going back to get away after everything has changed
--
: 大家好
: 小弟雖然會sudo指令操作
: 也會一點VI編輯器操作
: 不過有時候想寫一些程式(php之類)的話,還是覺得用GUI的編輯器比較方便
: 可是常常要存檔時會遇到權限問題(登入帳號已經是管理員了)
: 此時只好先存在一般路徑,再用終端機下sudo cp的指令複製過去
: 想請問一下如果在圖形介面裡,如何取得sudo操作權限呢?
: 目前常用的的redhat Enterprise 7 & Ubuntu 18.04
: 謝謝!
因為之前查 wine 相關的 FAQ 瞄到:
https://wiki.winehq.org/FAQ#Is_Wine_malware-compatible.3F
所以就剛好有了
用其他使用者權限(非 root)跑跑看 wine
的想法,雖然不知道效果如何
於是參考原文底下推文的討論,搭配 arch wiki 參考整理一些使用上的心得
首先剛開始在查時常看到:
: → : 在你的指令前加上gksu
類似的方法,但後來發現一些比較新的發行版似乎已經不用這個指令了
所以就使用了需要安裝 polkit 套件(有些發行版已經裝好了)的 pkexec 指令
大概步驟如下:
1. 在自己帳號的桌面開終端機輸入:
~$ xhost +
應該會出現: access control disabled, clients can connect from any host 的訊息
2. 確認要用的程式被 polkit 允許
參考: https://wiki.archlinux.org/index.php/Polkit#Actions
到 /usr/share/polkit-1/ 底下的 actions 或 rules.d 確認
自己要用的指令有沒有被 polkit 允許
沒有的話可以參考 wiki 裡面給的格式修改增加你要的指令
3. 確認自己的 $DISPLAY 變數
~$ echo $DISPLAY
應該會顯示等資訊
> ---
:0
> ---
4. pkexec 執行程式
就
pkexec --user <切過去的帳號> env DISPLAY=:0 <你要執行的指令>
例如想要用 gedit 編輯由 www-data 持有的 /var/www/html/index.html
就可以:
~$ pkexec --user www-data env DISPLAY=:0 gedit /var/www/html/index.html
或是我想要用 winewine 這個使用者來跑 wine 裡面的 IE
~$ pkexec --user winewine env DISPLAY=:0 wine iexplore
即可
==
至於相關環境變數要怎麼設定
目前想法是就一直加 env 變數=變數內容 像是:
~$ pkexec --user winewine env DISPLAY=:0 env WINEARCH=win32 wine winecfg
則是還不太確定,之後有需要再測試看看或看有沒有相關資料討論
也或許有其他比較easy的方法
但總之在這邊分享自己經驗以供參考
--
Paramore - Franklin
And when we get home, I know we won't be home at all
This place we live, it is not where we belong
And I miss who we were in the town that we could call our own
Going back to get away after everything has changed
--
Tags:
Linux
All Comments

By Bennie
at 2019-04-15T11:07
at 2019-04-15T11:07

By Lauren
at 2019-04-20T06:14
at 2019-04-20T06:14

By Isla
at 2019-04-24T13:30
at 2019-04-24T13:30

By Kristin
at 2019-04-27T20:27
at 2019-04-27T20:27

By Heather
at 2019-04-30T03:06
at 2019-04-30T03:06

By Caitlin
at 2019-05-02T21:13
at 2019-05-02T21:13

By Carolina Franco
at 2019-05-05T17:44
at 2019-05-05T17:44

By Hedwig
at 2019-05-08T09:04
at 2019-05-08T09:04

By Suhail Hany
at 2019-05-09T07:08
at 2019-05-09T07:08

By Todd Johnson
at 2019-05-11T20:03
at 2019-05-11T20:03

By Isabella
at 2019-05-15T21:12
at 2019-05-15T21:12

By Kristin
at 2019-05-17T07:04
at 2019-05-17T07:04

By Ophelia
at 2019-05-22T05:48
at 2019-05-22T05:48
Related Posts
如何redirect一個已經執行的prcoess輸出

By Oscar
at 2019-04-10T22:22
at 2019-04-10T22:22
類似卡鍵的問題

By Michael
at 2019-04-09T16:19
at 2019-04-09T16:19
hime 輸入法在manjaro出不來

By Linda
at 2019-04-08T13:08
at 2019-04-08T13:08
SMB這樣「轉接」會不會不妥

By Tracy
at 2019-04-06T17:56
at 2019-04-06T17:56
乙太網路

By Daph Bay
at 2019-04-06T00:38
at 2019-04-06T00:38