WSL使用ssh

  • ubuntu16.04(bash on window)

如果没有安装wsl(bash on ubuntu)参考win10 安装ubuntu子系统bash on ubuntu

Ubuntu最新子系统已集成ssh客户端和服务端,只需要简单配置

如果没有安装参考Ubuntu17.04 开启远程连接ssh服务端

  1. 备份sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
  2. 修改配置文件sudo vim /etc/ssh/sshd_config
1
2
3
4
Port 2200 # 端口改为2200,22端口已被占用
ListenAddress 0.0.0.0 # 取消注释
#StrictModes yes # 注释
PasswordAuthentication yes # 允许密码登录
  1. 启动ssh服务sudo service ssh start

  2. 检查服务ps -e |grep ssh 如果有sshd代表启动成功

  3. 测试是否可以连接ssh -p 2200 xuan@127.0.0.1用户名一般为wsl子系统@服务前面的名字,密码为系统登陆密码

  4. 如果需要远程连接需要开放防火墙端口2200

    参考:win10 远程访问tomcat,开放8080端口

mac升级之后git/ssh等用不了

错误日志

1
2
3
4
5
6
7
git clone git@gitlab.admin.xxxx.git
Cloning into 'transport-web'...
Unable to negotiate with 12.46.12.19 port 22: no matching host key type found. Their offer: ssh-rsa,ssh-dss
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

解决:执行vim ~/.ssh/config添加如下内容:

1
2
3
Host * 
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa

*代表允许任何主机使用 RSA

参考:SSH returns: no matching host key type found. Their offer: ssh-dss