My main computer is a Mac, but I run third party dev tools on a separate Debian box so they can't mess up my main computer. To control the Debian box from the Mac, I use SSH and VNC over Ethernet. The VNC session runs an Xfce desktop environment.
Mostly the remote control setup works great, but it's a pain to copy from macOS and paste to apps running in Xfce (macOS Screen Sharing VNC client app doesn't do clipboard sync). For example, suppose I want to copy text from Chrome on the Mac and paste it into VS Code on Debian. Since I can't paste directly into the VNC client, I must go through an SSH shell where pasting works fine.
In the past, I've used SSH to paste into vim and make a temporary file. But, today I figured out a better way where I can send text directly to the Xfce clipboard from my SSH shell:
cat <<'EOF' | DISPLAY=:1 xclip -selection clipboard
these are some lines
of text that I copied from Chrome
or ${WHEREVER}. <- this should pass through because of the single quotes
EOF
To make this easier to use, I defined an alias for xclip in my .bashrc file:
alias xclip='DISPLAY=:1 xclip -selection clipboard'
With the alias, I can do:
cat <<'EOF' | xclip
these are some lines
of text that I copied from Chrome
or ${WHEREVER}. <- this should pass through because of the single quotes
EOF
Notes:
- If you don't already have
xclipinstalled, you'll need tosudo apt install xclip - The
cat <<'EOF'stuff is using bash's heredoc string syntax. Note that in this case the single quotes around EOF are telling bash not to do its normal variable substitution. This is useful if you want to copy and paste code that includes bash variable syntax, perhaps as part of a Makefile. In this case,${WHATEVER}will get passed through toxcliprather than being evaluated as a variable substitution by bash. - I have TigerVNC server configured to set
DISPLAYto:1. Since the instance of bash that's running in my SSH shell is is not part of an X session, it doesn't know about TigerVNC's display. I have to tellxclipwhichDISPLAYto use, otherwise it would get mad and complain with an error message.
This page (Pasting in Hard Mode with VNC and SSH) was last updated on September 17, 2025.
Text editor powered by tinymce.