ETJava Beta | Java    注册   登录
  • github 设置SSH提交方式

    发表于 2025-06-02 15:30:46     阅读(149)     博客类别:Git

    github设置SSH登录

    1. 生成 SSH key

    ssh-keygen -t ed25519 -C "your_email@example.com"
    etjav@LAPTOP-3DC06KH4 MINGW64 ~/Desktop/finebi_demo (main)
    $ ssh-keygen -t ed25519 -C 'xx@xx.com'
    Generating public/private ed25519 key pair.
    Enter file in which to save the key (/c/Users/etjav/.ssh/id_ed25519):
    Created directory '/c/Users/etjav/.ssh'.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /c/Users/etjav/.ssh/id_ed25519.
    Your public key has been saved in /c/Users/etjav/.ssh/id_ed25519.pub.
    The key fingerprint is:
    SHA256:x/3dqAWQZAz/T5o7G3PBA+rXa3h9Alki3etDECJWvAafk xx@xx.com
    The key's randomart image is:
    +--[ED25519 256]--+
    |     ..o+=+      |
    |      =. *o.o    |
    |     . .o.+o.o   |
    |       .E.o=oo.  |
    |        S +.++=  |
    |         o  oO =.|
    |          . *oB.o|
    |           .oB+.o|
    |            +=...|
    +----[SHA256]-----+

    2. 将SSH Key添加到github

    将生成的公钥(通常在 ~/.ssh/id_ed25519.pub)添加到 GitHub
    
    登录 GitHub → Settings → SSH and GPG keys → New SSH key

    3. 修改远程地址为 SSH

    git remote set-url origin git@github.com:xxx/xxx.git
    
    例如:git remote set-url origin git@github.com:etjava/etjava_demo.git
    

    4. 推送到github

    git push origin main
    
    $ git push origin main
    The authenticity of host 'github.com (140.82.112.4)' can't be established.
    ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
    Are you sure you want to continue connecting (yes/no)? y
    Please type 'yes' or 'no': yes
    Warning: Permanently added 'github.com,140.82.112.4' (ECDSA) to the list of known hosts.
    Enumerating objects: 18, done.
    Counting objects: 100% (18/18), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (13/13), done.
    Writing objects: 100% (16/16), 9.61 KiB | 1.60 MiB/s, done.
    Total 16 (delta 1), reused 0 (delta 0)
    remote: Resolving deltas: 100% (1/1), done.
    To github.com:etjava/finebi_demo.git
       269734d..265b4c9  main -> main