2

I am trying to cut-paste some switch config over an ssh session from my mac. It seems to start mangling it after a set buffer size. Surely cut-paste buffer is large enough, since I can cut-paste just fine in other programs(even chrome terminal emulator for the same ssh session funny enough). Is there a way to increase this cut-paste buffer to a terminal on MacOS, or am I stuck cut-pasting in short bursts?

EDIT: So, after quite a bit of debugging of the kernel tty driver on the OS where I was connecting to, I found that the root cause of it was the specific tty implementation, which had only a small buffer (1k). As a result pasting anything larger would overrun that buffer and create the above mentioned problem. With chrome terminal emulator, it looks like it has its own buffer and just waits for a prompt and sends it line-by-line to the pty.

migrated from stackoverflow.com Sep 20 '15 at 17:03

This question came from our site for professional and enthusiast programmers.

  • What happens if you use pbpaste to send the data over the SSH session? – IKavanagh Aug 27 '15 at 20:20
  • It works yes, but is it really the solution? Basically that means that I have to log out from my switch and do the pbpaste | ssh admin@switch every time I have to paste something. – pinkstone Aug 27 '15 at 20:43
1

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
  • Really nice detailed writeup, but doesn't really help in my case. The device I am ssh'ing to is a network device where I don't have a root access and or OS on that said device doesn't have much in terms of prebuilt packages. I just refuse to believe that Apple didn't add the ability to increase terminal input buffer somewhere in the settings I guess. – pinkstone Aug 28 '15 at 17:29
  • Ah well, that was the best method I could find. I don't think your issue is OS X. I think it is on the external device but seen as though you don't have access I'm not sure what else I can suggest unless you send files across with scp or ftp. – IKavanagh Aug 29 '15 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.