如何创建X server重启的替代快捷键?避免误触CTRL+ALT+BACKSPACE
Got it, let's fix that super annoying accidental X server restart issue once and for all! Here's how you can set up a custom shortcut for restarting the X server—you can even keep (or ditch) the old Ctrl+Alt+Backspace combo, whatever works for you:
Method 1: Universal Xorg Config (Works for Most X11 Desktops)
This method sets the shortcut system-wide, so it'll work no matter which desktop environment you're using:
- Open your Xorg keyboard config file. Depending on your distro, this might be
/etc/X11/xorg.confor/etc/X11/xorg.conf.d/00-keyboard.conf. You'll need sudo access for this, so run something likesudo nano /etc/X11/xorg.conf.d/00-keyboard.confin the terminal. - Look for the
Section "InputClass"block (it should be there for your keyboard). Add or modify theXkbOptionsline to include your new shortcut. For example, to keep the old combo and add Ctrl+Shift+Backspace:
If you want to replace the old shortcut entirely, just removeOption "XkbOptions" "terminate:ctrl_alt_bksp,terminate:ctrl_shift_bksp"terminate:ctrl_alt_bkspfrom the line. You can also use other combinations liketerminate:alt_shift_bkspfor Alt+Shift+Backspace. - Save the file (in nano, that's
Ctrl+OthenEnter, followed byCtrl+Xto exit). Log out and back in, or restart your X server, and the new shortcut will take effect.
Method 2: Desktop Environment-Specific Shortcuts (More Intuitive)
If you prefer using your desktop's built-in settings tool, here's how to do it for popular environments:
GNOME
- Open Settings → Keyboard Shortcuts.
- Scroll all the way to the bottom and click Add Custom Shortcut.
- Name it something like "Restart X Server", then set the command to
sudo killall -TERM Xorg. (Note: You'll need to let your user run this command without a password first—see the tip below.) - Click Set Shortcut and press the combo you want (like Ctrl+Shift+Backspace), then hit Add.
KDE Plasma
- Open System Settings → Shortcuts → Custom Shortcuts.
- Click Edit → New → Global Shortcut → Command/URL.
- Name your shortcut, paste
sudo killall -TERM Xorgas the command, then switch to the Trigger tab and set your desired key combo.
Xfce
- Open Settings Manager → Keyboard → Application Shortcuts.
- Click Add, paste
sudo killall -TERM Xorgas the command, then press your preferred key combo when prompted.
Important Tip for the Desktop Method:
To avoid entering your password every time you use the shortcut, edit the sudoers file to allow the command without authentication:
- Run
sudo visudoin the terminal. - Add this line at the bottom (replace
your_usernamewith your actual username):your_username ALL=(ALL) NOPASSWD: /usr/bin/killall -TERM Xorg - Save and exit (in visudo, that's
Ctrl+OthenEnter, followed byCtrl+X).
Method 3: Temporary Shortcut (Current Session Only)
If you just want to test a new shortcut without changing any config files, run this in the terminal:
setxkbmap -option terminate:ctrl_shift_bksp
This enables Ctrl+Shift+Backspace for the current session only. To keep the old combo alongside it, use:
setxkbmap -option terminate:ctrl_alt_bksp,terminate:ctrl_shift_bksp
Quick Note:
Remember—restarting the X server will close all your open apps, so make sure you save your work before using any of these shortcuts!
内容的提问来源于stack exchange,提问作者Shayan

