Bash - Create Multiple SSH key Aliases for BitBucket

: ' Check if you have ssh ' ssh -v : ' Show your current keys ' ls -a ~/.ssh : ' Create new SSH key (identity) - enter password when prompted ' ssh-keygen -f ~/.ssh/personalid -C "personalid" : ' Create an SSH Config file to alias accounts ' sudo vim ~/.ssh/config : ' Type in your aliases Host <alias> HostName <bitbucket.org> IdentityFile ~/.ssh/<identity> ' Host workid HostName bitbucket.org IdentityFile ~/.ssh/workid IdentitiesOnly yes Host personalid HostName bitbucket.org IdentityFile ~/.ssh/personalid # Make sure to include `IdentitiesOnly` # if you are getting auth erorrs # and you know you ID is setup correctly. # It will hep bypass the default ID # as the first check. : ' Alternate config ' # Default GitHub user Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/personalid # Work user account Host bitbucket.org HostName bitbucket.org PreferredAuthentications publickey IdentityFile ~/.ssh/workid : ' Load Key into BitBucket `personalid` is what you named your ssh file in `~/.ssh`. `.pub` is the public key version you will paste the contents of, into bitbucket settings. ' # Show the contents that you can copy/paste cat ~/.ssh/personalid.pub # MacOSX can use pbcopy to copy the contents to your clipboard pbcopy < ~/.ssh/personalid.pub : ' Go to the BitBucket SSH settings, add a new key, and past the contents of the public key in there. URL: https://bitbucket.org/account/user/<username>/ssh-keys/ `<username>` is your username ' open https://bitbucket.org/account/user/<username>/ssh-keys/ : ' Usually your first clone, pull, fetch will require your password. So be sure to remember what that is. git clone git@<alias>:<team>/<project>.git ' git clone git@personalid:ATeam/Project.git

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.