https://smallstep.com/blog/ssh-agent-explained/ https://gist.github.com/ryuheechul/494f4e6f08eaca34ef00ab8b238eca2a#ssh-server
- https://github.com/maxgoedjen/secretive/blob/main/FAQ.md#how-do-i-tell-ssh-to-use-a-specific-key
- maxgoedjen/secretive#127 (comment)
- maxgoedjen/secretive#92 (comment)
- maxgoedjen/secretive#156 (comment)
- maxgoedjen/secretive#117 (comment)
Enter Keychain, https://www.funtoo.org/OpenSSH_Key_Management,_Part_2
https://esc.sh/blog/ssh-agent-windows10-wsl2/ or
# maybe in your .bashrc or .zshrc
eval $(keychain [--quiet] --eval --agents ssh [id_rsa])
assuming
pbcopy
&pbpaste
is what is used for clipboard on both systems
ssh remote-host pbpaste | pbcopy
pbpaste | ssh remote-host pbcopy
not strictly related to above, but I enjoyed reading this article, https://andrewbrookins.com/technology/synchronizing-the-ios-clipboard-with-a-remote-server-using-command-line-tools/ and hopefully iPad gets to have macOS one day, lol.
Even beyond simply accessing it, sharing clipboard is also possible via something called X11 forwaring.
A nice explanation is at https://askubuntu.com/a/305681.
# client side at ./ssh/config
ForwardX11 yes # make sure this is on
# server side at /etc/ssh/sshd_config
X11Forwarding yes # make sure this is on - this might be blocked by default on macOS host
# When an error occur like this
# ```
# Remote: No xauth program; cannot forward
# X11 forwarding request failed on channel 0
# ```
# and the host is macOS and xquartz is installed, this should help with error above
XAuthLocation /opt/X11/bin/xauth # or the path what `which xauth` returns
On macOS, there is no X11 server by default but it can be installed
I would install it by one of these ways:
nix-env -iA nixpkgs.xquartz
brew install --cask xquartz
Another important thing is that we need to know how to use clipboard on linux and that information can be found at https://ostechnix.com/access-clipboard-contents-using-xclip-and-xsel-in-linux/.
I prefer to use xsel
over xclip
.
And having xsel
is enough to make these two plugins work:
I also would make an alias to help my muscle memory used to macOS.
# bring `pbcopy` and `pbpaste` to linux
alias pbcopy='xsel -i -b'
alias pbpaste='xsel -o -b'
Now things copied inside ssh and vice versa!
Using after initial installation may require reboot (let me know if not)
xeyes
command to see if it's working (and it should run the app if it wasn't)
A timing could be little tricky that when it actually start working.
Check to see if xsel
(or xclip
if you prefer) is installed on the host system.
But bascially, when you run printenv DISPLAY
, you should see something like below.
# on the client side - in this case, macOS
$ printenv DISPLAY
/private/tmp/com.apple.launchd.xYzAbCde/org.xquartz:0
# on the ssh host side - in this case, linux
$ printenv DISPLAY
localhost:10.0
The selection should be CLIPBOARD not PRIMARY nor SECONDARY.
These should work
xclip [-i] [-o] -s clipboard
xclip [-i] [-o] -s c
xsel [-i] [-o] --clipboard
xsel [-i] [-o] -b
but not these:
xclip [-i] [-o]
xsel [-i] [-o]
pbcopy
and pbpaste
seems not work out of the box to forwarded X11 on the host side. (when it is on the client side it works)
xsel [-i] [-o] -b
still works though
Even after running XQaurtz on the host side and make sure it syncs clipboards. My speculation is that it's because even if it syncs, it syncs with the host X11 not the client's which makes sense to me.
I'm looking for an way to mitigate this as this could be annoying that plugins that I use automatically select pbcopy|paste
when they exist.
I inveted a workaround that uses these wrapper scripts:
- https://github.com/ryuheechul/dotfiles/blob/master/bin/local/pbcopy
- https://github.com/ryuheechul/dotfiles/blob/master/bin/local/pbpaste
They worked as I hoped for my use cases!
And now these plugins works on macOS host.
Just make sure those scripts are exported to $PATH
.
But this might break the sync between macOS clipboard and xsel -b
. I'm looking into it. I'm fine with the workaround for now.