Windows 11
git version 2.32.0.windows.2
GitHub 20240520
--
今天找回了自己的 GitHub 賬號密碼,繼續玩吧,再次加入 藍星的開源軟件基地。
使用郵箱註冊的,找回密碼也很方便。
本文簡要展示 按照官方文檔的介紹 使用 SSH 連接 GitHub 的過程。
簡述爲:
- 創建SSH密鑰對
- 公鑰註冊到GitHub,2次
- 測試SSH密鑰對
- 創建倉庫
- 拉取倉庫
- 提交代碼
主要文檔
1、Connecting to GitHub with SSH
https://docs.github.com/en/authentication/connecting-to-github-with-ssh
- About SSH
- Using SSH agent forwarding
- Managing deploy keys
- Checking for existing SSH keys
- Generating a new SSH key and adding it to the ssh-agent
- Adding a new SSH key to your GitHub account
- Testing your SSH connection
- Working with SSH key passphrases
2、Getting started with Git
https://docs.github.com/en/get-started/getting-started-with-git
- Set up Git
- Setting your username in Git
- Caching your GitHub credentials in Git
- Why is Git always asking for my password?
- Updating credentials from the macOS Keychain
- Git workflows
- About remote repositories
- Managing remote repositories
- Associating text editors with Git
- Configuring Git to handle line endings
- Ignoring files
- Git cheatsheet
使用 SSH 連接 GitHub
文檔1 下面的 “E. Generating a new SSH key and adding it to the ssh-agent”。
生成密鑰對文件命令:公鑰、私鑰
ssh-keygen -t ed25519 -C "[email protected]"
注,如果密鑰對文件已存在,則替換;也可以在 提示“Enter file in which to save the key (/c/Users/YOU/.ssh/id_ALGORITHM):[Press enter]”時輸入不同的。
注,在提示,“Enter passphrase (empty for no passphrase): [Type a passphrase]”時,直接按下 回車鍵, 意味着沒有 passphrase,存在安全風險。
上面命令執行後,在 HOME 目錄的 .ssh 目錄下生成了 下面兩個文件:
- id_ed25519 私鑰
- id_ed25519.pub 公鑰
其中,公鑰 需要添加到 GitHub 網站,見文檔1 的 “F. Adding a new SSH key to your GitHub account”。
說明,SSH key 有兩個用途,認證 和 上傳代碼等,每次添加,都只能選擇一個用途,因此,需要添加兩次——不過,兩次可以是同一個公鑰。
Authentication keys 和 Signing keys。
驗證是否配置成功
見文檔1 的 “G. Testing your SSH connection”。
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection
執行命令:
ssh -T [email protected]
說明,第一次會出現很長一串信息,輸入 yes 即可。在執行一次,信息就簡單了。兩次執行的輸出信息末尾都有:
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
--xxx 是 用戶名。
關於 ssh-agent
在 設置了 密鑰對的 passphrase 時,可以使用 ssh-agent 進行管理。
避免每次操作都要輸入 passphrase。
安全相關,重要。
使用代碼倉庫
見文檔2 中的內容。
安裝 git軟件,略。
git配置
見文檔2 的 “B. Setting your username in Git”:
https://docs.github.com/en/get-started/getting-started-with-git/setting-your-username-in-git
命令:
git config --global user.name "Mona Lisa"
$ git config --global user.name
--全局
git config user.name "Mona Lisa"
$ git config user.name
--單個庫 進入 庫目錄
見文檔“Setting your commit email address”:
命令:
git config --global user.email "YOUR_EMAIL"
$ git config --global user.email
--全局
git config user.email "YOUR_EMAIL"
$ git config user.email
--單個庫 進入 庫目錄
注意,其中有提到“a GitHub-provided noreply email address”,GitHub提供的無回覆郵件地址。可以配置到Git倉庫中。
這個郵件地址的格式也在文檔中有介紹,新的是“[email protected]”,如下:
注,ID找了半天沒找到,最後拉取倉庫後,使用 git log -3 命令看到了,而且這裏的 加號 是真的存在的。
創建倉庫
在 GitHub 官網,登錄後創建,很方便。
拉取倉庫到本地:SSH
選擇 倉庫的 Local - SSH 地址:
執行 git clone 拉取到本地 即可。
git clone [email protected]:xxx/hello-world.git
--
拉取後,配置 git 的 user.name、user.email。
ben發佈於博客園
提交代碼到GitHub
命令提交 或 IDE提交,皆可。
不再贅述。
END
本文鏈接:
https://www.cnblogs.com/luo630/p/18202797
ben發佈於博客園
ben發佈於博客園