1

I am running Lubuntu 16.04
How can I add a shortcut-key (Ctrl + Alt + BackSpace) to kill the X server?

To restart from the command line, I can do it using sudo pkill X. I must insert the password too.
I want to be able to restart the X server without typing in a password, and by using a shortcut key combination.

By the way, I tried adding the following to the ~/.config/openbox/lubuntu-rc.xml file, but it needs root.

<keybind key="C-A-BackSpace">
  <action name="Execute">
    <command>pkill X</command>
  </action>
</keybind>

I reload the settings using openbox --reconfigure. `

0

I guess you mean a desktop shortcut icon?

First make a new empty text file and paste this in to it

#!/bin/bash     

sudo pkill X

Save it as killx.sh in to your /home and run

sudo chown root.root killx.sh

Then

sudo chmod 4755 killx.sh

To set it so your user can still execute the file, this should be able to run as root without a password (source for root sh)

To make it a click-able icon, open a text file paste

[Desktop Entry]
Name=killx
Comment=runs_killx.sh
Exec=~/killx.sh
Icon=any_you_want
Terminal=false
Type=Application
Categories=Utility;Application;

Save this to your /home as killx.desktop and make it executable

sudo chmod +x killx.desktop

Now you can put the .desktop file anywhere you like and double click it to run the commands in killx.sh.

FYI you can add an icon for it by adding the path of the icon to killx.desktop.

0

sudo is command-line utility. Use gksu (not installed by default) or pkexec. Thus your shortcut now becomes

<keybind key="C-A-BackSpace">
  <action name="Execute">
    <command>pkexec pkill X</command>
  </action>
</keybind>
  • It asks for the sudo password. I want the shortcut to be without a password – Aryeh Beitz Aug 28 '16 at 12:26
  • Bad idea. If you put password into configuration, it will be saved in plain text. That means if somebody breaks into your system, they can read your password, and use your system for illegal activities. Not necessarily to steal your information, but to use your computer to attack others – Sergiy Kolodyazhnyy Aug 28 '16 at 12:53
0

This worked:

mkdir /usr/scripts

Create a file caled killX.sh.
It's contents should be:

#!/bin/bash
pkill X

Run this at the terminal to make the script executable

sudo chmod +x /usr/scripts/killX.sh

Now to set the script to be able to be run as root, but without a password, do the following: (I used this link, thanks @mark-kirby)

sudo visudo -f /etc/sudoers

Add this line to the end of the file

myusername ALL=NOPASSWD: /usr/scripts/killX.sh

The contents of ~/.config/openbox/lubuntu-rc.xml is now:

<keybind key="C-A-BackSpace">
  <action name="Execute">
    <command>sudo /usr/scripts/killX.sh</command>
  </action>
</keybind>

Thats it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.