I don't have a solution to increase the amount of data you can paste into an SSH session but I do have a workaround that might work for you. The workaround involves X11 forwarding and sharing the OS X clipboard with the X server pasteboard.
Set Up X11 Forwarding
To set up X11 Forwarding on your remote server you need to edit your /etc/ssh/sshd_config
file and change the line
#X11Forwarding no
to
X11Forwarding yes
You need to restart the SSH daemon after you update the /etc/ssh/sshd_config
file. Now we need to install xauth
on your remote server with the appropriate command for your platform
sudo pacman -S xorg-xauth # Arch-Linux
sudo apt-get install xauth # Debian/Ubuntu/etc.
sudo yum install xauth # RHEL/CentOS/Fedora/etc.
You can then connect to your server using the -X
, or -Y
options.
-X
will enable X11 forwarding.
-Y
will enable trusted X11 forwarding.
This step may or may not be needed depending on your version of OpenSSH. There is a known bug in OpenSSH that results in the message
X11 forwarding request failed on channel 0
when attempting to connect to a remote server with X11 forwarding. The fix is to edit your /etc/ssh/sshd_config
file and change the line
#X11UseLocalhost yes
to
X11UseLocalhost no
You should now be successfully able to connect to your remote server with X11 forwarding on.
Sharing the OS X and X Server Clipboards
To share the OS X keyboard with the X server we need to edit the file ~/Library/Preferences/org.x.X11.plist
or ~/Library/Preferences/org.macosforge.xquartz.X11.plist
depending on your version of OS X. You can use ls ~/Library/Preferences/ | grep X11
to determine which file you need to edit. We need to add 5 boolean keys to this
sync_clipboard_to_pasteboard
sync_pasteboard
sync_pasteboard_to_clipboard
sync_pasteboard_to_primary
sync_primary_on_select
The easiest way to add these is probably to use terminal commands
defaults write org.macosforge.xquartz.X11 sync_clipboard_to_pasteboard -boolean true
defaults write org.macosforge.xquartz.X11 sync_pasteboard -boolean true
defaults write org.macosforge.xquartz.X11 sync_pasteboard_to_clipboard -boolean true
defaults write org.macosforge.xquartz.X11 sync_pasteboard_to_primary -boolean true
defaults write org.macosforge.xquartz.X11 sync_primary_on_select -boolean true
replacing org.macosforge.xquartz.X11
with org.x.X11
if necessary. After making this change you also need to restart the X server, logging off your SSH session and quitting the application from the dock will suffice.
There also seems to be a bug in XQuartz that ships with later versions of OS X that requires you to start xclock
from the OS X terminal before the OS X and X server clipboards will be shared.
Copy and Pasting
Now everything is in place to copy and paste between the OS X clipboard and the X server clipboard. The last thing to do is install xclip
on your remote server and copy and paste to your hearts content.
The sequence you need to initialise copy and pasting is to first SSH to your remote server
$ ssh -X [user@]hostname
then in another terminal window run
$ xclock
^C
where ^C
stands for CTRL+C. Copy from OS X with pbcopy
or CMD+C and paste on your remote server with xclip
.
xclip -o
will print the contents of the clipboard to stdout
, whilst
xclip -i
will read from stdin
to the clipboard
pbpaste
to send the data over the SSH session?pbpaste | ssh admin@switch
every time I have to paste something.