Skip to content
Wenliang ZHANG edited this page Nov 30, 2022 · 2 revisions

SSH tunnel

  1. ssh to destination server through jump server in one session of WSL.
  2. create tunnel in another session of WSL.
$ ssh -NL 127.0.0.1:8000:remote:8000 -p 22 public@jump
public@jump's password:

Local 8000 is now mapped to destination server’s 8000.

SSH on VM

Make sure it is the correct distribution and version wanted. (CentOS 7.x, Ubuntu 18.04, etc.)

If the default ssh port is not 22, so make sure to access it with:

$ ssh -p <port> user@host
$ scp -P <port> from@host1:/foo user@host2:/baro

Look the case of the letter p/P!

SSH and X11

https://www.cyberciti.biz/faq/how-to-fix-x11-forwarding-request-failed-on-channel-0/

  1. WSL Linux

    Local /etc/ssh/ssh_config.

     19 Host *
     20     ForwardAgent yes
     21     ForwardX11 yes
     22     ForwardX11Trusted yes
    ...
     49     SendEnv LANG LC_*
     50     HashKnownHosts yes
     51     GSSAPIAuthentication yes
     52     XauthLocation /usr/bin/xauth
        
  2. SSH Server

    Remote /etc/ssh/sshd_config.

    X11Forwarding yes
    X11UseLocalhost no
    
    # Turn it on for passwd-less login using ed25519 and rsa etc.
    PubkeyAuthentication yes
    
    # Default is INFO
    LogLevel DEBUG
        

    To make the changes take effect.

    # kill -SIGHUP $(pgrep -f "sshd -D")
    Or
    # service sshd reload
        
  3. Debug on the client side
    $ ssh -X -v -v -v user@ip 
        

CentOS and selinx!

The client can’t login with rsa, ed25519 etc. And turn on the LogLevel to DEBUG in sshd_config, found sth. like,

# tail -f /var/log/secure
<snipped>
...sshd[52581]: debug1: Could not open authorized keys '/data/home/zedware/.ssh/authorized_keys': Permission denied
<snipped>

This comment from https://stackoverflow.com/questions/20688844/sshd-gives-error-could-not-open-authorized-keys-although-permissions-seem-corre saved the day.

I had the same problem with the same cause, but restorecon didn't work. 
I had to change the SELinux type explicitly. 
chcon -Rv -t ssh_home_t ~/.ssh – Jonathan

The non-default home path and selinux caused the problem.

SSH server on WSL

Install OpenSSL and register it as an automatic task in Windows, https://www.illuminiastudios.com/dev-diaries/ssh-on-windows-subsystem-for-linux/.

Clone this wiki locally