https://github.com/tarikguney/powershell-git-profile
Setting up SSH keys with Git in Powershell
https://github.com/tarikguney/powershell-git-profile
git github powershell ssh
Last synced: 3 months ago
JSON representation
Setting up SSH keys with Git in Powershell
- Host: GitHub
- URL: https://github.com/tarikguney/powershell-git-profile
- Owner: tarikguney
- Created: 2022-02-05T23:34:22.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-21T07:29:46.000Z (over 3 years ago)
- Last Synced: 2025-04-30T08:56:48.766Z (7 months ago)
- Topics: git, github, powershell, ssh
- Language: PowerShell
- Homepage:
- Size: 395 KB
- Stars: 17
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Git SSH Configurator for Powershell

Are you are tired of manually generating your public and private keys and starting the ssh agent and adding the private key to it each time you use remote Git repositories with SSH authentication?
Then, this is the script you need.
It will:
1. Generate your SSH public and private keys.
2. Add the necessary OpenSSH commands in your `$profile.CurrentUserCurrentHost` profile file so that each time you start a new Powershell session, your private SSH key are automatically added to OpenSSH agent.
3. It will copy your new SSH public key to the clipboard so that you can quickly paste it into your favorite Git registry SSH keys page (e.g. Github).
4. And more importantly, you won't have to remember any of these steps.
You can get more information by invoking `Get-Help ./setup.ps1` in the script folder.
## Examples
`./setup.ps1 -e hello@world.com`
`./setup.ps1 -e hello@world.com -f github_key`
For all examples, run:
`Get-Help ./setup.ps1 -Examples`
## Parameters
```
-Email (Alias: -e)
Email address that is used in the SSH Key.
-KeyFileName (Alias: -f)
The SSH public and private key file name that is going be generated. The default is github.
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
```
To see the parameter information, run:
`Get-Help ./setup.ps1 -Detailed`
## Notes
1. Works in MacOS and Windows
2. Powershell 7.x+ must be installed on the computer.
## Troubleshooting
If you are getting the following error even though you added your public key to your Git registery's SSH Keys:
```
Cloning into 'repository-name'...
Warning: Identity file /c/Users/Tarik Guney/.ssh/github not accessible: No such file or directory.
Warning: Permanently added 'bitbucket.org' (RSA) to the list of known hosts.
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
```
Then you are most likely using more than one keys. Follow the steps below:
1. If not exist, create a `config` file in `~/.ssh` folder.
2. Add the following code (adjust for your own needs):
```
Host github.com
Hostname github.com
IdentityFile ~/.ssh/github_beast
IdentitiesOnly yes
Host bitbucket.org
Hostname bitbucket.org
IdentityFile ~/.ssh/atlassian
IdentitiesOnly yes
```
If you want to see which public and private key are used for which host (bitbucket.org or github.com, etc.), then run the following commands:
```
$env:GIT_SSH_COMMAND = "ssh -vvv"
git clone your-remote-repo
```
Developed by [@tarikguney](https://github.com/tarikguney)