Its easy to run a command as other user in Linux.
But when you try to run a GUI application as other user, its not as simple as commandline.
The above command does not work because user 'bakki' do not have necessary permission to work with X server running on other user.
Here is a difference, When compare to Windows OS, In Linux OS, X Server, which is responsible to draw in video hardware runs as a client in a given user with given permissions.
All the GUI applications sends the drawing request to the X server via X protocols. So if the X Server running user do not provide permission, No other user application can contact the X Server for display. This is the reason GUI applications fails to run as a other user using simple command line.
Solution: Provide X Server permission to users and run the command.
It is particularly useful to run vlc media player under root account in linux. vlc will not run as a root but for some reason, if you need to run the vlc under root desktop login in linux, you can use following way,
KDE:
sudo -u bakki id uid=1000(bakki) gid=1000(bakki) groups=1000(bakki),10(wheel),18(dialout)
But when you try to run a GUI application as other user, its not as simple as commandline.
sudo -u bakki kwrite No protocol specified kwrite: cannot connect to X server :0
The above command does not work because user 'bakki' do not have necessary permission to work with X server running on other user.
Here is a difference, When compare to Windows OS, In Linux OS, X Server, which is responsible to draw in video hardware runs as a client in a given user with given permissions.
All the GUI applications sends the drawing request to the X server via X protocols. So if the X Server running user do not provide permission, No other user application can contact the X Server for display. This is the reason GUI applications fails to run as a other user using simple command line.
Solution: Provide X Server permission to users and run the command.
CMD="kwrite"; USER=bakki;xhost +SI:localuser:$USER; sudo -u $USER -H -b $CMD >/dev/null 2>&1
It is particularly useful to run vlc media player under root account in linux. vlc will not run as a root but for some reason, if you need to run the vlc under root desktop login in linux, you can use following way,
CMD="vlc";USER=bakki;xhost +SI:localuser:$USER; sudo -u $USER -H -b $CMD >/dev/null 2>&1
If you do not like to use the inbuilt commands, You can always use KDE / GNOME provided utilities to run Linux GUI applications as a other user. Its simple as well,
KDE:
kdesu -u bakki firefox
No comments:
Post a Comment