Creates the related GitHub's SSH configuration on drive C
.
- Create a new directory to store your credentials inside the
C
drive (/
), then create a hidden.ssh
directory inside it:
# Create directories
mkdir "/MyGitHub"
cd "/MyGitHub"
mkdir ".ssh"
# Create a new config file
New-Item "/MyGitHub\.ssh\config" -ItemType "file"
- Create SSH Keys using
ssh-keygen
:
ssh-keygen -t ed25519 -C YourGitHubEmail@Domain.com
- Enter the absolute path (full path) where you want to store SSH Keys inside the
.ssh
folder:
C:\MyGitHub\.ssh\id_ed25519
- Choose a passphrase, don't forget it! You may need to enter it on every pull/push/commit.
- Add SSH Keys to
ssh-agent
:
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent
ssh-add /MyGitHub\.ssh\id_ed25519
- Open Public Key & copy its content:
Get-Content /MyGitHub\.ssh\id_ed25519.pub
- Open https://github.com/settings/keys & then click on New SSH key, enter any title, Key Type: Authentication Key, then paste the content you copied from previous step (Public Key) inside Key field & click on Add SSH key.
- Make the
.ssh
folder more secure:
# Set hidden attribute for the .ssh folder
Set-ItemProperty -Path "/MyGitHub\.ssh" -Name "Attributes" -Value ([System.IO.FileAttributes]::Hidden)
# Remove existing permissions
$folderPath = "/MyGitHub\.ssh"
$acl = Get-Acl $folderPath
$acl.Access | ForEach-Object { $acl.RemoveAccessRule($_) }
# Add permissions for yourself
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$env:USERNAME", "FullControl", "Allow")
$acl.SetOwner([System.Security.Principal.NTAccount]"$env:USERNAME")
$acl.SetAccessRule($rule)
# Save the modified ACL
Set-Acl $folderPath $acl
- Change default SSH path to your preferred path:
@'
Host github.com
IdentityFile /MyGitHub\.ssh\id_ed25519
'@ | Out-File -FilePath "/MyGitHub\.ssh\config" -Encoding utf8
- Test GitHub connection:
ssh -i C:\MyGitHub\.ssh\id_ed25519 -T git@github.com