Setup: I use iTerm2 on MacOS to connect to a remote server. The remote server runs tmux, in which I open files and edit in vim sessions.

Problem: I can't copy/paste between the remote tmux session and the local iTerm client. I can use iTerm 2's alt/option + mouse selection to select text, but this copies over multiple vim panes/tmux panes - bad.

Is there any elegant solution to make selections in tmux panes synchronize between the remote pasteboard and the local (MacOS pasteboard)? I've seen reattach-to-user-namespace, but I'm pretty certain it doesn't do what I want.

  • 3
    Is this really a tmux problem? Seems to me like you'd have the same issue in general connecting over ssh alone.
    – kejadlen
    Apr 3, 2012 at 4:30
  • 3
    It may not be a tmux problem, but it is a workflow problem. I can't be the only one who has this exact problem - which is why I'm wondering what other people are doing to get around it.
    – bhargav
    Apr 3, 2012 at 18:33

4 Answers 4


So, when you ssh into the server, you can use reverse tunneling so that you can talk back to your OSX machine to send it commands do pbcopy.

ssh -R 1234:localhost:22 remoteServer

Replace 1234 with any open port the remote server. Then on the remote server, you can then run:

tmux save-buffer - | ssh -p 1234 localhost pbcopy

That should connect back to OSX and send the contents of your tmux copy buffer to it. You may want to use ssh keys to prevent typing your password to your OSX machine.

If that works for, you can then create your tmux keybindings.

bind C-c run "tmux save-buffer - | ssh -p 1234 localhost pbcopy"

I should note, for this to work, you will need to turn on Remote Sharing in OSX.

Secondary Option:

Since you're using OSX, if you're also using iTerm2, you might consider installing http://code.google.com/p/iterm2/downloads/detail?name=tmux-for-iTerm2-20120203.tar.gz&can=2&q= on your servers.

It's basically a custom tmux what supports the "-C" flag. This flag hands over windows, and panes and all their splitting to iTerm2.


I think that this problem was solved in a better way:


  • Workable solution.
    – j4hangir
    Feb 16, 2017 at 18:15

A simpler method

  1. Enable XQuartz to sync clipboard
  2. Use X11 forwarding when you connect to the remote server
  3. Have a binding like in your tmux.conf: bind-key C-c run ‘tmux show-buffer | xsel -pbi'
    • where the X clipboard of your choice is after the pipe

You can do a similar binding in vim if you wish, as well


Edit 02-10-2020:

Due to this issue I recommend Jason Axelson's answer! It's the best solution (as of 2020).

Original Answer:

Thanks to pope's answer, I tried the tmux -C hint.

  1. You don't have to install anything, because the current tmux version supports the -C flag.
  2. Use -CC, because -C isn't always working.

So with tmux -CC (or tmux -CC attach) tmux is even better than it already is.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .