Skip to content

July 2021

Windows-10 port forwarding

Below is the command to port-forward in Windows-10. It can be executed in normal command-prompt not in PowerShell. Make sure you've administrator privilege. This will be useful in when you run a VM in your Windows workstation. So you can directly ssh to the VM instead of opening RDB every time.

netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=18001 connectaddress=192.168.105.115 connectport=22

Now this machine forwards any incoming connection on port number 18001 to 192.168.105.115 IP's port 22. To ssh into the machine 192.168.105.115 from an external network, you should issue the following command (provided that windows machine IP is 112.172.29.29).

 $ ssh 112.172.29.29 -p 18001

Copy paste in tmux session inside ssh

When you access your tmux session on a remote machine from different client machines, based on the client machine configuration and terminal, etc., some features will not work. One of them is copy-paste.

I used to have tmux-yank configured to xclip. But it didn't work will when I accessed my remote VM from a Windows machine running putty. Similarly I had to configure every new machine I start using which was time consuming. Majority of my copy-paste activities will be between tmux panes and windows. I don't usually copy from the local machine to the remote machine. So I used this simple hack.

Configured my .tmux.conf to redirect yank-ed to a temporary file as below.

bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'cat > /tmp/clipboard'

Configured .zshrc to load an environment variable from that temporary file on every prompt.

precmd() { export p=`cat /tmp/clipboard` }

So if I copy any text in tmux using y, it will be populated into a environmental variable named p.

NOTE: As the environmental variable will be loaded upon next prompt only, after copying, you need to press enter once it to take effect

Below gif will show how it works tmux copy paste hack