Last active
July 31, 2026 09:07
-
-
Save morkev/3f08cf45f38610565455bf48190b1b7e to your computer and use it in GitHub Desktop.
Fix Linux Keychron Error: HID Device Connected [K]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # ============================================================================== | |
| # KEYCHRON LINUX FIX F0R HID DEVICE C0NNECTED [K] | |
| # Author: morkev | |
| # | |
| # Contributors: | |
| # - SIMULATAN: Fixed dongle interference by filtering out "Link" devices. | |
| # - karoltheguy: Added SELinux context reset (restorecon) to prevent silent blocks. | |
| # - wanjas: Verified 'input' group addition is required for distros like Pop_OS. | |
| # - Veliion: Simplifying the script for multiple devices (mice, dongles) at once. | |
| # - pyr0bot: Added an interesting case to support ONEofZERO Keychron boards. | |
| # - sthouement: Added STM32 DFU bootloader udev rule to fix firmware flashing freezes. | |
| # | |
| # INSTRUCTIONS | |
| # | |
| # Step 1: Open your terminal and create the file: | |
| # nano fix-keychron.sh | |
| # | |
| # Step 2: Paste this entire script into the nano editor. | |
| # | |
| # Step 3: Save and Exit nano | |
| # Press Ctrl + O to save. | |
| # Press Enter to confirm. | |
| # Press Ctrl + X to exit. | |
| # | |
| # Step 4: Make executable and run | |
| # chmod +x fix-keychron.sh | |
| # sudo ./fix-keychron.sh | |
| # ============================================================================== | |
| # --- 1. SUDO THIS PUPPY --- | |
| if [ "$EUID" -ne 0 ]; then | |
| echo "Please run this script with sudo: sudo ./fix-keychron.sh" | |
| exit 1 | |
| fi | |
| # --- 2. SETUP VARIABLES --- | |
| REAL_USER=${SUDO_USER:-$USER} | |
| USER_GROUP=$(id -gn "$REAL_USER") | |
| RULE_FILE="/etc/udev/rules.d/99-keychron.rules" | |
| # --- 3. FIND KEYCHRON VEND0R ID --- | |
| echo "Looking for Keychron devices..." | |
| # Grab the first Keychron or ONEofZERO device found to extract the Vendor ID. | |
| # Using grep -iE allows us to check for multiple manufacturer names at once. | |
| KEYCHRON_INFO=$(lsusb | grep -iE "Keychron|ONEofZERO" | head -n 1) | |
| if [ -z "$KEYCHRON_INFO" ]; then | |
| echo "No Keychron device detected. Please ensure it is plugged in via USB." | |
| exit 1 | |
| fi | |
| echo "Found: $KEYCHRON_INFO" | |
| # Extract the Vendor ID | |
| VENDOR_ID=$(echo "$KEYCHRON_INFO" | awk '{print $6}' | cut -d':' -f1) | |
| echo "Authorizing Vendor ID: $VENDOR_ID" | |
| # --- 4. APPLY UDEV RULES --- | |
| echo "Creating udev rule at $RULE_FILE..." | |
| # Write the rule dynamically based only on Vendor ID. | |
| # This ensures mice, keyboards, and dongles all work with one rule. | |
| cat <<EOF > "$RULE_FILE" | |
| # Keychron Keyboard/Mouse udev rule for VIA / Keychron Launcher | |
| KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="$VENDOR_ID", MODE="0660", GROUP="$USER_GROUP", TAG+="uaccess", TAG+="udev-acl" | |
| # STM32 DFU bootloader rule (Keychron firmware flashing support) | |
| SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE="0660", GROUP="$USER_GROUP", TAG+="uaccess", TAG+="udev-acl" | |
| EOF | |
| # Reset SELinux context (if applicable for your case) | |
| if command -v restorecon &> /dev/null; then | |
| echo "Resetting SELinux context for the udev rule..." | |
| restorecon -v "$RULE_FILE" | |
| fi | |
| echo "Reloading udev rules..." | |
| udevadm control --reload-rules | |
| udevadm trigger | |
| # --- 5. PERMISSIONS --- | |
| echo "Adding $REAL_USER to the 'input' group..." | |
| usermod -aG input "$REAL_USER" | |
| # --- 6. YOU SHOULD BE GOOD --- | |
| echo "Done! All your Keychron devices should now be accessible." | |
| echo "IMPORTANT: Please unplug your device(s) and plug them back in for the changes to take full effect." |
Author
Thanks for your comments, everyone! Really appreciate them.
I updated the code (Revision #6) to handle that special case @pyr0bot mentioned and gave them credits for it- supporting the ONEofZERO boards Keychron manufactures.
@sthouement also found the STM32 DFU bootloader udev rule to fix firmware flashing freezes, at least a behavior that occurs in Ubuntu, and of course also gave them credits for this.
Please let me know if you find anything and will make sure to update this so your efforts help others.
Amazing, thank you! This was what made it finally work for me after trying so many things
Thanks so much for this!
Thanks so much! It works
Worked flawlessly. Fedora 44
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I have a Linux Ubuntu and had the same issue (not being able to run the keychron launcher and another similar issue : the firmware updates that did not work either:
Fixed quite the same way with an additional rule. Here is the full udev rule that fixes both issues :
FILE
/etc/udev/rules.d/70-keychron.rules