我想git push通過一個命令在 Ubuntu 上運行,例如:
echo -e "email\ntoken" | git push origin branchName
git push origin branchName && email && token
但是在命令之后我必須輸入我的電子郵件:

uj5u.com熱心網友回復:
如何使用 ssh 密鑰輕松推送到/從 GitHub 拉取
你需要:
- 將您的遠程配置為使用 GitHub 存盤庫地址的 ssh 版本而不是 http 版本。
- 生成公鑰/私鑰 ssh 密鑰對,并通過 Web 瀏覽器手動將公鑰添加到您的 GitHub 帳戶。
細節
將您的遠程配置為使用 GitHub 存盤庫地址的 ssh 版本而不是 http 版本。例如:對于我的這個 repo:https ://github.com/ElectricRCAaircraftGuy/eRCaGuy_hello_world ,使用這個 ssh URL:[email protected]:ElectricRCAAircraftGuy/eRCaGuy_hello_world.git 而不是這個 HTTPS:https ://github.com/ ElectricRCAircraftGuy/eRCaGuy_hello_world.git:
# View your current remote servers and their URLs git remote -v # Set your `origin` remote server to use the ssh URL instead # of the HTTPS one git remote set-url origin https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world.git生成公鑰/私鑰 ssh 密鑰對,并通過 Web 瀏覽器手動將公鑰添加到您的 GitHub 帳戶。在此處查看我關于 ssh 內容的完整說明:https ://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/tree/master/home/.ssh
# generate a public/private ssh key pair ssh-keygen -t ed25519 -C "[email protected]" # Ensure the ssh-agent is running (this starts the `ssh-agent`) eval "$(ssh-agent -s)" # Add your private key to it; update the path to your private key below, as # required, based on what path you interactively selected above when # generating the key ssh-add ~/.ssh/id_ed25519 # Verify what keys have been added to the ssh-agent by listing # (`-l`) currently-added keys. # A. If you see "Could not open a connection to your authentication agent.", # it means the `ssh-agent` has not been started yet, so you must start it # with `eval "$(ssh-agent -s)"`. # B. If you see "The agent has no identities.", it means the ssh-agent is # running but you haven't added any ssh keys to it, so run `ssh-add # path/to/private_key` to add a key to the agent. ssh-add -l現在在 Web 瀏覽器中登錄 github 并單擊您的個人資料圖片 --> 設定 --> SSH 和 GPG 密鑰(左側)--> 新 SSH 密鑰 --> 復制并粘貼您的 .pub 密鑰檔案的內容(例如:
cat ~/.ssh/id_ed25519.pub在你的 Ubuntu 機器上運行以讀取公鑰——如果你使用不同的檔案名,根據需要調整該路徑)到 GitHub 中——> 單擊“添加 SSH 密鑰”。現在,每當您鍵入時,
git push它都會使用您的 ssh 密鑰自動運行。
參考
- 我完整的 ssh 筆記:https ://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/tree/master/home/.ssh
uj5u.com熱心網友回復:
您可以將用戶名作為 https git 遠程地址的一部分提供一次。
首先運行git remote -vv以獲取完整的當前遠程 URL。
然后要更改現有的遙控器,您可以執行以下命令:
git remote set-url origin https://[email protected]/yourname/yourrepo.git
新部分在哪里yourname@(替換您的 github 用戶名)并且 URL 的其余部分應該與中所示的相同git remote -vv
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/530848.html
下一篇:帶有符號鏈接的Git存盤庫
