How to Share One Monitor Between Two Computers Using KVM Switch on Linux 2025

Prerequisites

Before touching a single cable, confirm you have everything on this list. Missing even one item — especially EDID emulation support on your KVM — will cause hours of frustration.

  • [ ] KVM switch with EDID emulation (TESmart HKS0401A, UGREEN CM655, or equivalent) — firmware 2023+ recommended
  • [ ] DisplayPort 1.4 or HDMI 2.1 cables (two per KVM input port) — cheap cables cause signal drops at high refresh rates
  • [ ] USB-A or USB-C hub passthrough on the KVM — essential so keyboard/mouse share without a second KVM or Bluetooth adapter
  • [ ] Linux distro: Ubuntu 22.04/24.04, Fedora 40+, or Arch Linux (kernel 6.1+)
  • [ ] Packages: xrandr, autorandr, input-remapper, xclip or wl-clipboard, pactl (PipeWire or PulseAudio)
  • [ ] SSH access between both machines on the same LAN (for clipboard sync in Step 5)

| KVM Model | Max Resolution | EDID Emulation | USB Hub Ports | Linux Tested | |---|---|---|---|---| | TESmart HKS0401A | 4K@60Hz | Yes | 4× USB-A | Ubuntu 24.04, Arch | | UGREEN CM655 | 4K@60Hz | Yes | 2× USB-A | Ubuntu 22.04, Fedora 40 | | CKLau 8-Port | 1080p@60Hz | No | 4× USB-A | Limited — EDID issues | | Level1Techs KVM | 4K@144Hz | Yes (DP 1.4) | 4× USB-A | All major distros |

Note: USB hub passthrough means the KVM exposes a USB hub to whichever computer is active. This lets your keyboard and mouse reconnect automatically without needing a separate USB switch. Without it, you'd need to physically replug peripherals.

Estimated time: 45–60 minutes for a full setup including automation scripts.


Step 1: Choose and Connect Your KVM Switch

Getting the physical wiring right is the foundation. An incorrect cable or a KVM without EDID emulation will make every subsequent step painful, so invest five minutes here to get it right.

Selecting a KVM Switch: Budget vs. Feature-Rich Options in 2025

For a Linux developer workstation in 2025, you have two realistic tiers:

Budget (~$40–$80): The UGREEN CM655 and TESmart HKS0401A are the most-reported-working units in Linux forums. Both support 4K@60Hz over HDMI 2.0 and include EDID emulation, which prevents the display reset problem covered in Step 2.

Feature-rich (~$150–$300): The Level1Techs DP 1.4 KVM supports 4K@144Hz and has been explicitly designed with Linux in mind. It uses DisplayPort 1.4 DSC compression to fit 4K@144Hz within the bandwidth envelope, and its EDID emulation is rock-solid. If you're running a 1440p@165Hz or 4K@144Hz panel, this is the only budget-adjacent option that reliably works.

Physical Connection: Hooking Up Monitor, Keyboard, Mouse, and USB Devices

Here's the exact wiring topology:

Computer A ──[DP/HDMI]──┐
                        ├── KVM Switch ──[DP/HDMI]── Monitor
Computer B ──[DP/HDMI]──┘

Computer A ──[USB-A]──┐
                      ├── KVM USB Hub ──[USB-A]── Keyboard
Computer B ──[USB-A]──┘                └──[USB-A]── Mouse

Plug the monitor into the KVM's output port, not directly into either computer. Both computers connect to the KVM's input ports. Your keyboard and mouse plug into the KVM's shared USB hub output.

DisplayPort 1.4 vs HDMI 2.1: DP 1.4 gives you 32.4 Gbps, enough for 4K@120Hz without DSC or 4K@144Hz with DSC. HDMI 2.1 on most KVM switches is limited to the HDMI 2.0 spec (18 Gbps) despite the label, which caps you at 4K@60Hz. Always verify the KVM's actual spec sheet, not just the port label.

Verifying Display Signal on Both Computers

After wiring, press the KVM's physical button to toggle between inputs. On each computer, run:

xrandr --query

You should see your monitor listed with its native resolution. If you see disconnected or only low resolutions like 1024×768, EDID emulation is either disabled or broken on your KVM — check the KVM firmware settings before proceeding.


Step 2: Fix the EDID / Display Reset Problem on Linux

This is the single biggest Linux-specific pain point with KVM switches. Every time you switch away and back, Linux sees the monitor disconnect and reconnect, triggering a full display reconfiguration that forgets your layout, scaling, and refresh rate settings.

Why Linux Resets Your Display Layout Every Time You Switch Inputs

When a KVM switch cuts the video signal, the monitor's EDID (Extended Display Identification Data) disappears from the GPU's perspective. The kernel logs a hotplug event, the display server tears down the output, and when you switch back, it rebuilds from scratch — often defaulting to a suboptimal resolution. KVMs with EDID emulation send a fake EDID signal to the GPU continuously, but cheaper models stop emulating when the input is inactive.

Installing and Configuring xrandr Persistence with a Startup Script

Create a shell script that enforces your desired display configuration:

#!/usr/bin/env bash
# ~/.config/scripts/monitor-setup.sh
# Adjust OUTPUT, resolution, and rate to match your setup

OUTPUT="DP-1"           # Run xrandr --query to find your output name
RES="2560x1440"
RATE="144"

xrandr --output "$OUTPUT" \
       --mode "${RES}" \
       --rate "${RATE}" \
       --primary \
       --pos 0x0

Make it executable and add it as an autostart entry:

chmod +x ~/.config/scripts/monitor-setup.sh
mkdir -p ~/.config/autostart

Create ~/.config/autostart/monitor-setup.desktop:

[Desktop Entry]
Type=Application
Name=Monitor Setup
Exec=/home/youruser/.config/scripts/monitor-setup.sh
X-GNOME-Autostart-enabled=true
Hidden=false
NoDisplay=false

Replace youruser with your actual username. This restores your layout on login, but not on mid-session KVM switches — that's what autorandr handles.

Using autorandr to Auto-Restore Monitor Profiles on X11

Install autorandr:

# Ubuntu/Debian
sudo apt install autorandr

# Fedora
sudo dnf install autorandr

# Arch
sudo pacman -S autorandr

Set up your display exactly as you want it (using xrandr or your display settings GUI), then save the profile:

autorandr --save primary

Now create a post-switch hook that autorandr calls whenever it detects a display change. Create the directory and script:

mkdir -p ~/.config/autorandr/primary/
cat > ~/.config/autorandr/primary/postswitch << 'EOF'
#!/usr/bin/env bash
# Runs after autorandr restores the "primary" profile
# Re-apply xrandr settings in case EDID came back dirty
sleep 1
xrandr --output DP-1 --mode 2560x1440 --rate 144 --primary --pos 0x0
# Restart your compositor or panel if needed
# pkill -HUP polybar
EOF
chmod +x ~/.config/autorandr/primary/postswitch

Enable the autorandr systemd service so it fires on display hotplug events:

systemctl --user enable --now autorandr.service

Note: On Wayland with sway, use kanshi instead of autorandr. Define output profiles in ~/.config/kanshi/config and run kanshi as a sway startup command. GNOME Wayland handles display profiles natively but doesn't restore them on KVM hotplug — see the Common Issues section for a workaround.


Step 3: Configure Input Remapper for Hotkey Switching

Physically pressing the KVM button breaks your flow. Input Remapper lets you trigger the switch with a keyboard shortcut — no hands leaving the keyboard, no reaching for the box under the desk.

Installing Input Remapper on Ubuntu, Fedora, and Arch Linux

# Ubuntu 22.04/24.04
sudo apt install input-remapper

# Fedora 40+
sudo dnf install input-remapper

# Arch (AUR)
yay -S input-remapper-git

Start and enable the service:

sudo systemctl enable --now input-remapper

Mapping a Custom Keyboard Shortcut to Trigger KVM Input Switch

Many KVM switches accept USB HID commands or respond to specific key sequences (often Scroll Lock × 2 followed by a number key) to switch inputs. Check your KVM manual — TESmart and UGREEN both support hotkey sequences.

Create an Input Remapper preset config at ~/.config/input-remapper/presets/default/kvm-switch.json:

{
  "mappings": [
    {
      "input_combination": [
        {"type": 1, "code": 70, "analog_threshold": null}
      ],
      "output_type": null,
      "output_symbol": "KEY_SCROLLLOCK",
      "target_uinput": "keyboard",
      "macro": "repeat(2, key(KEY_SCROLLLOCK)); key(KEY_1)",
      "name": "KVM Switch to Computer 1",
      "comment": "Double Scroll Lock then 1 — switches KVM to port 1"
    }
  ]
}

Alternatively, if your KVM exposes a serial or USB control interface, point the macro at a script:

{
  "macro": "exec(/home/youruser/.config/scripts/kvm-switch.sh 1)",
  "name": "KVM Switch Port 1"
}

Where kvm-switch.sh sends the appropriate HID command or uses usb-hid-relay for KVMs with relay control.

Running Input Remapper as a systemd Service for Auto-Start

Input Remapper ships with a system service, but you need a user-level service to load your preset on login:

# ~/.config/systemd/user/input-remapper-autoload.service
[Unit]
Description=Load Input Remapper KVM preset
After=input-remapper.service

[Service]
Type=oneshot
ExecStart=/usr/bin/input-remapper-control --command start --device "Your Keyboard Name" --preset kvm-switch
RemainAfterExit=yes

[Install]
WantedBy=default.target
systemctl --user enable --now input-remapper-autoload.service

Note: Find your exact keyboard device name by running input-remapper-control --list-devices. The name must match exactly, including capitalization.


Step 4: Automate the USB Switch with a udev Rule

When the KVM switches inputs, the USB hub it exposes to your Linux machine disappears and reappears. You can intercept this kernel event with udev to trigger scripts automatically — including switching your audio output.

Understanding How KVM USB Hubs Appear to the Linux Kernel

Run lsusb before and after switching your KVM to identify the hub's vendor and product IDs:

lsusb | grep -i "hub\|kvm\|tesmart\|ugreen"
# Example output:
# Bus 003 Device 005: ID 05e3:0610 Genesys Logic, Inc. Hub

Note the idVendor (05e3) and idProduct (0610). These are what udev will match against. To confirm it's your KVM hub specifically, run udevadm info -a -n /dev/bus/usb/003/005 and look at the full attribute tree.

Writing a udev Rule to Trigger a Script on Device Connect/Disconnect

Create /etc/udev/rules.d/99-kvm-switch.rules:

# /etc/udev/rules.d/99-kvm-switch.rules
# Fires when the KVM USB hub is attached to this machine (i.e., KVM switched to us)
SUBSYSTEM=="usb", \
  ACTION=="add", \
  ATTRS{idVendor}=="05e3", \
  ATTRS{idProduct}=="0610", \
  RUN+="/usr/local/bin/kvm-connected.sh"

SUBSYSTEM=="usb", \
  ACTION=="remove", \
  ATTRS{idVendor}=="05e3", \
  ATTRS{idProduct}=="0610", \
  RUN+="/usr/local/bin/kvm-disconnected.sh"

Reload udev rules:

sudo udevadm control --reload-rules && sudo udevadm trigger

Syncing Audio Output Switch Alongside the KVM Switch

Create /usr/local/bin/kvm-connected.sh:

#!/usr/bin/env bash
# /usr/local/bin/kvm-connected.sh
# Runs as root via udev — use runuser or sudo -u to switch audio as the correct user

USER_NAME="youruser"  # Replace with your username
USER_ID=$(id -u "$USER_NAME")

export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/${USER_ID}/bus"
export PULSE_RUNTIME_PATH="/run/user/${USER_ID}/pulse"

# Get the sink name for your speakers/headphones
# Run: pactl list sinks short  — to find the correct sink name
SINK_NAME="alsa_output.pci-0000_00_1f.3.analog-stereo"

runuser -l "$USER_NAME" -c \
  "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/${USER_ID}/bus \
   pactl set-default-sink '$SINK_NAME'"

# Also restore monitor layout
runuser -l "$USER_NAME" -c \
  "DISPLAY=:0 XAUTHORITY=/home/${USER_NAME}/.Xauthority \
   autorandr --change"
sudo chmod +x /usr/local/bin/kvm-connected.sh

Note: udev scripts run as root with a minimal environment. Always explicitly set DBUS_SESSION_BUS_ADDRESS and DISPLAY when calling user-space tools like pactl or xrandr.


Step 5: Sync Clipboard Between Two Computers Over the Network

A hardware KVM switches your display, keyboard, and mouse — but clipboard contents stay locked to whichever computer was active when you copied. Fixing this requires a network-based solution.

Why KVM Hardware Alone Cannot Sync Your Clipboard

The clipboard lives in the display server's memory (X11 selections or Wayland's wl-data-device). When the KVM switches inputs, the clipboard on Computer A is inaccessible from Computer B's keyboard — they're separate memory spaces with no hardware bridge. You need either a software KVM overlay or an SSH pipe.

Setting Up wl-clipboard / xclip with a Netcat or SSH Pipe

For X11, add these aliases to ~/.bashrc on both machines:

# ~/.bashrc on Computer A (IP: 192.168.1.10)
# Push local clipboard to Computer B
alias clip-push='xclip -o -selection clipboard | \
  ssh user@192.168.1.11 "xclip -selection clipboard -i"'

# Pull clipboard from Computer B to local
alias clip-pull='ssh user@192.168.1.11 \
  "xclip -o -selection clipboard" | \
  xclip -selection clipboard -i'

For Wayland, swap xclip with wl-paste and wl-copy:

alias clip-push='wl-paste | ssh user@192.168.1.11 "wl-copy"'
alias clip-pull='ssh user@192.168.1.11 "wl-paste" | wl-copy'

You can bind clip-push to a keyboard shortcut via your desktop environment or input-remapper, so switching the KVM and syncing the clipboard becomes a single chord.

Using Barrier or Input Leap (Open-Source Synergy Fork) as a Software Alternative

If you find yourself running clip-push constantly, consider Input Leap — the community-maintained fork of Barrier (itself a fork of Synergy). It creates a software KVM over your LAN, sharing mouse, keyboard, and clipboard seamlessly:

# Server (Computer A)
sudo apt install input-leap
# Configure via GUI: set server IP, add client screen

# Client (Computer B)
sudo apt install input-leap
# Point to server IP in GUI

Input Leap handles clipboard sync, hotkey switching, and even drag-between-screens. Trade-off vs hardware KVM: Input Leap requires both machines to be on and networked; it can't switch a 4K@144Hz monitor signal, and there's latency over Wi-Fi. Use hardware KVM for display and peripherals, Input Leap purely for clipboard if you want the best of both.


Common Issues & Fixes

Error: Monitor Goes Black for 5+ Seconds When Switching

Cause: Your KVM lacks real EDID emulation and the GPU waits for the monitor's handshake signal to return.

Fix: Enable EDID emulation in your KVM's OSD menu. If unavailable, use xrandr --addmode to pre-register the mode and force it:

# Force the mode to persist even when monitor appears disconnected
xrandr --newmode "2560x1440_144" 586.00 2560 2752 3024 3488 1440 1443 1448 1514 -hsync +vsync
xrandr --addmode DP-1 2560x1440_144

Alternatively, flash a KVM firmware update — TESmart releases updates via their support portal specifically for this issue.

Error: Keyboard and Mouse Stop Working After Switch

Cause: USB re-enumeration takes 2–4 seconds, and some input daemons (iBus, fcitx) crash on device disappearance.

Diagnose with:

dmesg | grep -E "usb|input" | tail -30
# Look for: "USB disconnect" followed by "new full-speed USB device"

Fix: Add usbcore.autosuspend=-1 to your kernel parameters to prevent USB autosuspend from interfering:

# /etc/default/grub — add to GRUB_CMDLINE_LINUX_DEFAULT
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash usbcore.autosuspend=-1"
sudo update-grub

Error: KVM Switch Not Detected on Wayland GNOME/KDE — Monitor Profile Reverts

Cause: GNOME Wayland's mutter doesn't fire monitor-changed events the same way X11 does; autorandr won't work.

Fix with kanshi (sway/wlroots compositors):

sudo pacman -S kanshi  # or: sudo apt install kanshi
mkdir -p ~/.config/kanshi
# ~/.config/kanshi/config
profile primary {
  output DP-1 mode 2560x1440@144Hz position 0,0 scale 1
}

For GNOME Wayland, use dconf to force persistent display settings:

gsettings set org.gnome.mutter experimental-features "['scale-monitor-framebuffer']"

Then file the display profile via GNOME Settings — GNOME 46+ persists monitor configs by display serial number, so EDID emulation on the KVM is the real fix.

Error: Audio Does Not Switch Automatically

Cause: PipeWire tracks audio sinks by node name, not device insertion order.

Fix: Find your sink's PipeWire node name and target it directly:

pw-cli list-objects | grep -A5 "Audio/Sink"
# Note the node.name value
pactl set-default-sink "alsa_output.pci-0000_00_1f.3.analog-stereo"

| Symptom | Likely Cause | Fix Command | |---|---|---| | Black screen 5s on switch | No EDID emulation | xrandr --addmode + KVM firmware update | | Keyboard/mouse dead after switch | USB re-enumeration delay | usbcore.autosuspend=-1 in kernel params | | Wrong resolution after switch | autorandr not running | systemctl --user restart autorandr | | Audio stuck on wrong output | PipeWire sink not switching | pactl set-default-sink <node-name> | | Wayland profile not persisting | mutter hotplug event missing | Use kanshi or GNOME 46+ native profiles |


FAQ

Q: Can I share a 4K 144Hz monitor between two computers with a KVM switch?

Yes, but your hardware choices are constrained. DisplayPort 1.4 has 32.4 Gbps of bandwidth; 4K@144Hz at 10-bit color requires ~48 Gbps uncompressed, so you need DSC (Display Stream Compression) support in both your GPU and the KVM. The Level1Techs DP 1.4 KVM and certain TESmart models support DSC passthrough. HDMI 2.0 KVMs marketed as "HDMI 2.1" typically top out at 4K@60Hz in practice. Verify the KVM's spec sheet lists "4K@144Hz DSC" explicitly — not just "supports 4K" — before purchasing.

Q: Do I need a KVM switch if both computers are on the same network?

Not necessarily. Input Leap (the open-source Synergy successor) can share keyboard, mouse, and clipboard over LAN using a software KVM approach — no hardware required. It works well for developers who only need peripheral sharing and clipboard sync. However, it cannot switch a physical monitor signal, so both displays must remain powered. If desk real estate is the constraint, a hardware KVM is the only solution that truly gives you one monitor, one keyboard, one mouse with zero compromise on display quality or refresh rate.

Q: Will a KVM switch work with a Mac and a Linux machine simultaneously?

Yes, most modern KVM switches are OS-agnostic at the hardware level. The complication is EDID: macOS has its own display profile reset behavior that differs from Linux. When you switch back to the Mac, it may renegotiate the display timing rather than restoring the previous mode, which manifests as a resolution change or HiDPI scaling reset. The fix on macOS is a tool like BetterDummy or DisplayBuddy that persists display configurations independent of hotplug events. On the Linux side, the autorandr setup described in Step 2 handles this cleanly. Keyboard hotkey sequences from Input Remapper work transparently across both OSes since the KVM interprets them at the hardware level.