I've been messing around with PAM module on Kubuntu 18.04 (basically Ubuntu 18.04) and can't seem to figure out why suddenly I have permission issues running my bash script whenever user does sudo
command.
Here is my /usr/local/bin/test.sh
file code:
#!/bin/sh
/usr/bin/zenity --info --text="It Works!"
And here is my /etc/pam.d/sudo
file code:
#%PAM-1.0
session required pam_env.so readenv=1 user_readenv=0
session required pam_env.so readenv=1 envfile=/etc/default/locale user_readenv=0
# My PAM test runs here
auth required pam_exec.so /bin/bash /usr/local/bin/test.sh
@include common-auth
@include common-account
@include common-session-noninteractive
Whenever I try sudo -i
it returns me this error message:
bin/bash failed: exit code 126
asks for password and when correct password is entered, prints another error line:
bin/bash failed: exit code 126
I double checked that /usr/bin/test.sh
has all necessary permissions.
My question is - what am I doing wrong here? How can I correctly call this and trigger zenity message box as a test?
Here are some fixes i've tried without a success:
/usr/bin/test.sh
permissions are: -rwx--x--x 1 root root
#!/bin/sh
and #!/bin/bash
work"DISPLAY=:0"
didn't helpAllright one step closer to fixing it, but still having issues:
I added stdout
after auth required
and it fixed the issue if I use echo
for example, but if I run /usr/bin/zenity --info --text="It Works!"
it prompts out a new error:
Unable to init server: Could not connect: Connection refused (zenity:5046):
Gtk-WARNING **: 05:52:37.200: cannot open display: /bin/bash failed: exit code 1
No display defined for Zenity to prompt the message in.
Add display for whatever visual scripting you're doing within bash - in my case it was appending --display=:0.0
for zenity like so:
#!/bin/sh
/usr/bin/zenity --info --text="It Works!" --display=:0.0