cd ~/.ssh
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/user/.ssh/id_rsa): bitbucket_rsa
Enter passphrase (empty for no passphrase): [type passphrase]
Enter same passphrase again: [retype passphrase]
Your identification has been saved in bitbucket_rsa.
Your public key has been saved in bitbucket_rsa.pub.
The key fingerprint is:
SHA256:9GgssyHwEA0z3Stwmqc56RGsBujvSIDkcdO8OWYXlsa [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|..=+1. . |
|oo+*+o.+ |
|*.=*o =.o |
|++=+oG.+ o |
|o..==.* S . |
| .=. . * |
|..o. . |
| . . |
| |
+----[SHA256]-----+
ls
output
id_rsa id_rsa.pub
-
To start the agent, run the following:
eval `ssh-agent`
output
Agent pid 9700
-
Add keys
MacOS
ssh-add -K ~/.ssh/bitbucket_rsa
output
Enter passphrase for /Users/user/.ssh/bitbucket_rsa: Identity added: /Users/user/.ssh/bitbucket_rsa ([email protected])
Linux
ssh-add ~/.ssh/<private_key_file>
-
So that your computer remembers your password each time it restarts, open (or create) the
~/.ssh/config
file and add these lines to the file:... Host * AddKeysToAgent yes UseKeychain yes #macOS only
Add to ~/.ssh/config
Host git-codecommit.*.amazonaws.com
User [SSH key ID]
IdentityFile ~/.ssh/codecommit_rsa
Host bitbucket.org
User [bitbucket-user]
IdentityFile ~/.ssh/bitbucket_rsa
Host github.com
User wmakeev
IdentityFile ~/.ssh/github_rsa
Access CodeCommit repositories in multiple AWS accounts with SSH credentials
Host codecommit-1
Hostname git-codecommit.us-east-1.amazonaws.com
User SSH-KEY-ID-1 # SSH Key ID you copied from IAM (for example, APKAEIBAERJR2EXAMPLE1)
IdentityFile ~/.ssh/codecommit_rsa
Host codecommit-2
Hostname git-codecommit.us-east-1.amazonaws.com
User SSH-KEY-ID-2
IdentityFile ~/.ssh/codecommit_2_rsa
-
Copy the contents of your public key file
cat ~/.ssh/bitbucket_rsa.pub | pbcopy
-
Add key
-
Verify your configuration and username
CodeCommit
ssh git-codecommit.us-east-2.amazonaws.com
or with multiple credentials
ssh codecommit-2
Bitbucket
ssh -T [email protected]
Github
ssh -T [email protected]
Sample output (type "yes" when prompt)
The authenticity of host 'bitbucket.org (18.234.32.156)' can't be established. RSA key fingerprint is SHA256:zzCQOXSRBEiUtuE6AikHYKwbHaxvSc0ojez9YXaRp1A. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'bitbucket.org,18.234.32.156' (RSA) to the list of known hosts. Enter passphrase for key '/home/pi/.ssh/bitbucket_rsa': logged in as [username]. You can use git or hg to connect to Bitbucket. Shell access is disabled.
Url format:
[email protected]:<account_name>/<repo_name>.git
or
ssh://[email protected]/<account_name>/<repo_name>.git
GitHub
git clone [email protected]:teamsinspace/documentation-tests.git
CodeCommit
git clone ssh://git-codecommit.eu-west-1.amazonaws.com/v1/repos/MyDemoRepo my-demo-repo
With multiple credentials, you will be able to replace git-codecommit.eu-west-1.amazonaws.com
with codecommit-2
.
git clone ssh://codecommit-2/v1/repos/YourRepositoryName
To set up a remote for your repository
git remote add origin ssh://codecommit-2/v1/repos/YourRepositoryName
Bitbucket
-
From a terminal, navigate to the repository.
cd ~/<path_to_repo>
-
Run git remote -v to see the current remote URL.
git remote -v
output
origin https://[email protected]/tutorials/tutorials.git.bitbucket.org.git (fetch) origin https://[email protected]/tutorials/tutorials.git.bitbucket.org.git (push)
-
Update the remote URL with git remote set-url using the current and new remote URLs.
git remote set-url origin [email protected]:tutorials/tutorials.git.bitbucket.org.git
If you update your URL from HTTPS to SSH, next time you push or pull from your repository, the terminal responds that it is adding the Bitbucket host to the list of known hosts. You also won't have to enter a password.
-
Switch to your repository's directory
cd /path/to/your/repo
-
Connect your existing repository to Bitbucket
git remote add origin [email protected]:[username]/[repository].git git push -u origin master