Sudo
從 xbindkeys 呼叫的腳本呼叫 sudo
我有一個 macbook pro,我正在綁定腳本來控制鍵盤上的背光級別。我寫了 2 個腳本,它們執行良好,我只是無法讓它們在按鍵上執行。我在配置文件中使用名為 .xbindkeysrc 的配置文件設置並執行了 xbindkeys 我嘗試將腳本綁定到我的特殊功能鍵(與 fn 相同的行)。我知道我的配置文件載入正確,因為當我執行它時,
xbindkeys -s
它顯示了兩個目前不起作用的嘗試綁定。這是 my.xbindkeysrc 文件的內容########################### # xbindkeys configuration # ########################### # # Version: 0.1.3 # # If you edit this, do not forget to uncomment any lines that you change. # The pound(#) symbol may be used anywhere for comments. # # A list of keys is in /usr/include/X11/keysym.h and in # /usr/include/X11/keysymdef.h # The XK_ is not needed. # # List of modifier (on my keyboard): # Control, Shift, Mod1 (Alt), Mod2 (NumLock), # Mod3 (CapsLock), Mod4, Mod5 (Scroll). # # Another way to specifie a key is to use 'xev' and set the # keycode with c:nnn or the modifier with m:nnn where nnn is # the keycode or the state returned by xev # # This file is created by xbindkey_config # The structure is : # # Remark # "command" # m:xxx + c:xxx # Shift+... #keystate_numlock = enable #keystate_scrolllock = enable #keystate_capslock = enable "bash /opt/keyLightInc.sh" m:0x0 + c:238 XF86KbdBrightnessUp "bash /opt/keyLightDec.sh" m:0x0 + c:237 XF86KbdBrightnessDown # # End of xbindkeys configuration
我從詳細選項開始。這是輸出:
screen 0 for window 259 Start program with fork+exec call sudo: no tty present and no askpass program specified
如果您的
sudoers
文件設置了該requiretty
選項,那麼您只能從終端呼叫 sudo。如果您的
sudoers
文件沒有設置該requiretty
選項,那麼您可以從任何地方呼叫 sudo,但如果它提示輸入密碼,則需要終端。消息“sudo: no tty present and no askpass program specified”表示 sudo 嘗試提示您輸入密碼,但失敗了。您可以通過
-A
選項告訴 sudo 使用不同的方法來提示您輸入密碼。由於您在 X11 中執行,您可以使用ssh-askpass
隨 OpenSSH 分發的程序,它會在 X11 視窗中提示輸入密碼。sudo -A /usr/bin/ssh-askpass whatever-command-you-need-to-execute-as-root