1. Archlinux开启ssh服务

  1. 安装openssh
    pacman -Sy openssh

  2. 修改 /etc/ssh/sshd_config

    PermitRootLogin yes
    PubkeyAuthentication yes
    PasswordAuthentication yes
    
  3. 自启动
    systemctl enable sshd

2. VSCode配置Remote-ssh

  1. 选择设置 Remote.SSH:Show Login Terminal

    image-jcmf.png

  2. 配置ssh

    image-wxvd.png

    # Read more about SSH config files: https://linux.die.net/man/5/ssh_config
    Host Archlinux
      HostName 192.168.76.151
      User root
      Port 22
      IdentityFile "C:\Users\XSS\.ssh\id_rsa"
    

3. 设置公钥

  1. 生成公钥

    1. 安装Git
    2. 使用Git Bash生成密钥
      ssh-keygen
      #生成的私钥和公钥存储在`C:\Users\PC\.ssh`,分别为`id_rsa`和`id_rsa.pub`
      
  2. 安装公钥

    # Archlinux
    cat id_rsa.pub >> authorized_keys
    chmod 600 authorized_keys
    
  3. 设置公钥访问

    • 使用Git Bash
      ssh-copy-id -i .ssh/id_rsa.pub username@hostname

4. 使用

  1. 远程连接

    image-rfan.png

    image-gggm.png

  2. 新建终端

    image-xazc.png

  3. 打开远程目录作为工作区

    image-whcy.png