Skip to content

Instantly share code, notes, and snippets.

@morkev
Created February 17, 2026 20:30
Show Gist options
  • Select an option

  • Save morkev/3f08cf45f38610565455bf48190b1b7e to your computer and use it in GitHub Desktop.

Select an option

Save morkev/3f08cf45f38610565455bf48190b1b7e to your computer and use it in GitHub Desktop.
Fix Linux Keychron Error: HID Device Connected [K]
#!/bin/bash
# ==============================================================================
# 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
# ==============================================================================
# Ensure the script is run with sudo privileges
if [ "$EUID" -ne 0 ]; then
echo "Please run this script with sudo: sudo ./fix-keychron.sh"
exit 1
fi
# Get the actual user who ran the sudo command
REAL_USER=${SUDO_USER:-$USER}
USER_GROUP=$(id -gn "$REAL_USER")
echo "Looking for Keychron devices..."
# Extract Vendor and Product IDs using lsusb
KEYCHRON_INFO=$(lsusb | grep -i "Keychron" | head -n 1)
if [ -z "$KEYCHRON_INFO" ]; then
echo "No Keychron keyboard detected. Please ensure it is plugged in via USB."
exit 1
fi
echo "Found: $KEYCHRON_INFO"
# Parse the exact Vendor and Product IDs
VENDOR_ID=$(echo "$KEYCHRON_INFO" | awk '{print $6}' | cut -d':' -f1)
PRODUCT_ID=$(echo "$KEYCHRON_INFO" | awk '{print $6}' | cut -d':' -f2)
echo "Vendor ID: $VENDOR_ID"
echo "Product ID: $PRODUCT_ID"
RULE_FILE="/etc/udev/rules.d/99-keychron.rules"
echo "Creating udev rule at $RULE_FILE..."
# Write the rule dynamically based on your specific keyboard
cat <<EOF > "$RULE_FILE"
# Keychron Keyboard udev rule for VIA / Keychron Launcher
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="$VENDOR_ID", ATTRS{idProduct}=="$PRODUCT_ID", MODE="0660", GROUP="$USER_GROUP", TAG+="uaccess", TAG+="udev-acl"
EOF
echo "Reloading udev rules..."
udevadm control --reload-rules
udevadm trigger
echo "Adding $REAL_USER to the 'input' group..."
usermod -aG input "$REAL_USER"
echo "Done! Your Keychron should now be accessible."
echo "IMPORTANT: Please unplug your keyboard and plug it back in for the changes to take full effect."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment