Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ Simplify Your Dev Life with Git, SSH & GPG: How to Work with Multiple Code Hosts and Sign Your Commits with Ease

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š Simplify Your Dev Life with Git, SSH & GPG: How to Work with Multiple Code Hosts and Sign Your Commits with Ease


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

Managing multiple Git hosts can be challenging, especially when using different GPG and SSH keys. This article will walk you through the process of generating SSH and GPG keys, adding them to the local SSH agent and remote Git hosts, configuring multiple hosts to use different keys, and configuring the local Git to use multiple GPG keys for different Git hosts.

Generating SSH keys

If you have SSH keys already generated and added to your remote host and local SSH agent, you can skip and move to the next heading, otherwise, you can follow below to have the SSH setup:

  1. Open a terminal and run the following command to generate a new SSH key:

    ssh-keygen -t rsa -b 4096 -C "[email protected]"
    
  2. Follow the prompts to choose a location for the key file and to set a passphrase. The default options are usually sufficient.

  3. Once the key is generated, run the following command to display the public key:

    cat ~/.ssh/id_rsa.pub
    
  4. Copy the entire contents of the public key to your clipboard.

Adding SSH Key to the remote host

On the website of the code host, navigate to your account settings and find the option to add a new SSH key. Paste the public key into the input field and save the key.

Adding SSH key to the your SSH agent

  1. Open a terminal and run the following command to start the SSH agent

    eval "$(ssh-agent -s)"
    
  2. Add it to the agent

    ssh-add ~/.ssh/id_rsa
    

You can repeat the above for the multiple Git hosts you deal with so each host has different SSH Key.

Auto configure the SSH Key per host

When working with multiple code hosts, such as GitHub, GitLab, and Bitbucket, it can be helpful to have a separate host entry for each host in your ~/.ssh/config file. This allows you to easily switch between hosts without having to remember different URLs or SSH keys.

Here's an example of how to set up multiple hosts in your ~/.ssh/config file:

Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/github_rsa

Host gitlab.com
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/gitlab_rsa

Host bitbucket.org
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/bitbucket_rsa

Generating the GPG Keys

If you have GPG keys already generated and added to your remote host, you can skip and move to the next heading, otherwise, you can follow below to have the GPG setup:

  1. Open a terminal and run the following command to generate a new GPG key:

    gpg --full-generate-key
    
  2. Follow the prompts to enter your name and email address.

  3. Choose the key type and key size. The default options are usually sufficient.

  4. Set the expiration date for your key. You can choose to set no expiration or a specific date.

  5. Enter a passphrase for your key. This passphrase is required to use the key to sign commits.

  6. Once the key is generated, run the following command to get the key ID

    gpg --list-secret-keys --keyid-format LONG <your_email>
    
  7. In the output, identify the sec line, and copy the GPG key ID. It begins after the / character. In this example, the key ID is 4EC9DCE00DD4D021

    sec   rsa4096/4EC9DCE00DD4D021 2023-04-23 [SC]
      0A96E925578EA97AD6B62FA54EC9DCE00DD4D021
    uid                 [ultimate] User <user email>
    ssb   rsa4096/BBF655FD113EEE28 2023-04-23 [E]
    

Adding GPG Key to the remote host

  1. Open a terminal and run the following command to get your GPG public key

    gpg --armor --export <your_key_id>
    
  2. On the website of the code host, navigate to your account settings and find the option to add a new GPG key.

  3. Paste the public key into the input field and save the key.

Auto detect commit signing key

To make the process of signing the commits easier, you can configure your Git settings to use different keys for different hosts.

To do this, you can create multiple .gitconfig files and use the includeIf directive to specify the conditions under which each file should be used. For example, you can create a .gitconfig-work file for your work account and a .gitconfig-personal file for your personal account, and use the includeIf directive to specify that the .gitconfig-work file should be used for commits to your work repository and the .gitconfig-personal file should be used for commits to your personal repository. You can also configure each gitconfig file to use a different GPG key for signing commits.

includeIf is a configuration option in Git that allows you to include additional configuration files based on certain conditions. For example, you can include a specific configuration file based on the repository configuration you're working in.

Here's an example of how to set up multiple gitconfig files with includeIf:

  1. Create a separate gitconfig file for each signing key you want to use. For example, ~/.gitconfig-personal and ~/.gitconfig-work.
  2. In your main ~/.gitconfig file, add the following
# ~/.gitconfig
[includeIf "hasconfig:remote.*.url:[email protected]:**/**"]
    path = .gitconfig-work
[includeIf "hasconfig:remote.*.url:https://gitlab.com/**"]
    path = .gitconfig-work
[includeIf "hasconfig:remote.*.url:[email protected]:**/**"]
    path = .gitconfig-personal
[includeIf "hasconfig:remote.*.url:https://github.com/**"]
    path = .gitconfig-personal
# ~/.gitconfig-personal
[user]
    name = <YOUR NAME>
    email = <YOUR PERSONAL EMAIL>
    signingkey = <GPG KEY ID FOR PERSONAL GPG>
[commit]
    gpgsign = true
# ~/.gitconfig-work
[user]
    name = <YOUR NAME>
    email = <YOUR WORK EMAIL>
    signingkey = <GPG KEY ID FOR WORK GPG>
[commit]
    gpgsign = true

Conclusion

As a developer, working with multiple code hosts and signing your commits with multiple GPG keys can be challenging. However, by configuring your Git and SSH settings to use different keys for different hosts, you can simplify your workflow and increase your productivity. By following the steps outlined in this post, you can easily manage multiple code hosts, sign your commits with the appropriate GPG key, and use the appropriate SSH key for each host. This can help you save time and avoid mistakes, and ultimately make you a more effective developer. So why not give it a try? With a little bit of setup, you can streamline your workflow and take your development skills to the next level.

...



๐Ÿ“Œ Simplify Your Dev Life with Git, SSH & GPG: How to Work with Multiple Code Hosts and Sign Your Commits with Ease


๐Ÿ“ˆ 150.68 Punkte

๐Ÿ“Œ Git: The complete guide to sign your commits with an ssh key


๐Ÿ“ˆ 48.46 Punkte

๐Ÿ“Œ How to Use SSH Keys and 1Password to Sign Git Commits


๐Ÿ“ˆ 47.79 Punkte

๐Ÿ“Œ Verifying Git commits using GPG


๐Ÿ“ˆ 44.32 Punkte

๐Ÿ“Œ Git Squash Commits โ€“ Squashing the Last N Commits into One Commit


๐Ÿ“ˆ 42.68 Punkte

๐Ÿ“Œ A clean Git history with Git Rebase and Conventional Commits


๐Ÿ“ˆ 37.12 Punkte

๐Ÿ“Œ GNOME gnome-keyring 3.4.0/3.4.1 gkd-gpg-agent-ops.c gpg-cache-method idle/timeout access control


๐Ÿ“ˆ 36.63 Punkte

๐Ÿ“Œ gpg-tui v0.6.0 release - supports importing GPG keys from the clipboard


๐Ÿ“ˆ 36.63 Punkte

๐Ÿ“Œ How to install GPG (gnupg2) on a Debian Linux to fix gpg command not found error


๐Ÿ“ˆ 36.63 Punkte

๐Ÿ“Œ [OC]Linux kernel commits as of 5.7-rc1 by author's email domain name,for domains with &gt;= 5000 commits.


๐Ÿ“ˆ 35.7 Punkte

๐Ÿ“Œ Unqiue pair of SSH/GPG keys or multiple ones?


๐Ÿ“ˆ 33.97 Punkte

๐Ÿ“Œ Signatur-Lรถsung fรผr Git-Commits von Keeper Security - Dev-Insider


๐Ÿ“ˆ 33.62 Punkte

๐Ÿ“Œ [OC]Linux kernel commits as of 5.7-rc1 by author's email domain name,for domains with >= 5000 commits.


๐Ÿ“ˆ 33.34 Punkte

๐Ÿ“Œ Simplify Life: Your Life-hack Playbook?


๐Ÿ“ˆ 32.73 Punkte

๐Ÿ“Œ How these two Google Docs features can simplify your work life


๐Ÿ“ˆ 32.07 Punkte

๐Ÿ“Œ Git Stash Magic: Navigating Code Emergencies and Context Switches with Ease


๐Ÿ“ˆ 30.49 Punkte

๐Ÿ“Œ Defending Your Commits From Known CVEs With GitGuardian SCA And Git Hooks


๐Ÿ“ˆ 30.21 Punkte

๐Ÿ“Œ Whatโ€™s new in sign-up and sign-in (Chrome Dev Summit 2019)


๐Ÿ“ˆ 30.11 Punkte

๐Ÿ“Œ Mystery Git ransomware appears to blank commits, demands Bitcoin to rescue code


๐Ÿ“ˆ 29.88 Punkte

๐Ÿ“Œ git switch and git checkout โ€“ How to switch branches in git


๐Ÿ“ˆ 29.79 Punkte

๐Ÿ“Œ Two malicious Python libraries caught stealing SSH and GPG keys (ZDNet)


๐Ÿ“ˆ 29.74 Punkte

๐Ÿ“Œ How do you stay up to date on SSH, GPG, TLS algorithms and ciphers?


๐Ÿ“ˆ 29.74 Punkte

๐Ÿ“Œ How do you stay up to date on SSH, GPG, TLS algorithms and ciphers?


๐Ÿ“ˆ 29.74 Punkte

๐Ÿ“Œ Two malicious Python libraries were stealing SSH and GPG keys


๐Ÿ“ˆ 29.74 Punkte

๐Ÿ“Œ Two Malicious Python Libraries Caught Stealing SSH and GPG Keys


๐Ÿ“ˆ 29.74 Punkte

๐Ÿ“Œ Two malicious Python libraries caught stealing SSH and GPG keys | ZDNet


๐Ÿ“ˆ 29.74 Punkte

๐Ÿ“Œ Two Malicious Python Packages Steal SSH and GPG Keys Exists in the Python Package Index for a Year


๐Ÿ“ˆ 29.74 Punkte

๐Ÿ“Œ Streamlined Guide: Setting Up SSH and GPG Keys onย GitHub


๐Ÿ“ˆ 29.74 Punkte

๐Ÿ“Œ ssh-context - Bash wrapper around ssh which provides you ability to use contexts (as in kubectl) for SSH.


๐Ÿ“ˆ 28.96 Punkte

๐Ÿ“Œ Enhance your git log with conventional commits


๐Ÿ“ˆ 28.44 Punkte

๐Ÿ“Œ Enhance your git log with conventional commits


๐Ÿ“ˆ 28.44 Punkte

๐Ÿ“Œ Git commit helper: add emojis to your commits


๐Ÿ“ˆ 28.44 Punkte

๐Ÿ“Œ t3n Daily: Adobe &amp;amp; Figma, Ethereum &amp;amp; NFT, Steuer &amp;amp; Homeoffice, KI &amp;amp; Gruselfrau


๐Ÿ“ˆ 28.38 Punkte











matomo