Home Server/Docker Gtihub SSH Configuration
Post
Cancel

Server/Docker Gtihub SSH Configuration

在服务器/Docker容器上配置ssh,通过ssh方式连接Github

服务器端配置

  1. 安装Git,ssh等 (已安装可跳过)
    1
    
    sudo apt update && sudo apt install git openssl openssh-server -y
    
  2. Git 用户配置 (已配置可跳过)
    1
    2
    
    git config --global user.name "YOUR USERNAME"
    git config --global user.email "YOUR EMAIL"
    
  3. 生成密钥
    1
    
    ssh-keygen -t rsa -C "YOUR EMAIL"
    

    一路回车即可,公钥保存在 ~/.ssh/id_rsa.pub

    1
    
    cat ~/.ssh/id_rsa.pub
    

    复制公钥信息用于填到Github上

  4. 配置 config 文件
    1
    
    vi ~/.ssh/config
    

    粘贴以下内容

    1
    2
    3
    4
    5
    6
    
    Host github.com
    User git
    Hostname ssh.github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
    Port 443
    

Github上配置

Github -> Settings -> SSH and GPG keys, 或者访问 SSH and GPG keys

添加SSH,Key 填入前面复制的公钥,保存,之后便可以通过Github的SSH的链接克隆项目了

This post is licensed under CC BY 4.0 by the author.