Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Take in account
- ssh is the ssh client
- sshd is the ssh server
- then, you should notice where you need to configure
- ======================================================
- To configure ssh with Forwarding
- ======================================================
- https://help.ubuntu.com/community/SSH/OpenSSH/Configuring#Forwarding
- https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding
- ======================================================
- To configure ~/.ssh/config with ServerAliveInterval
- ======================================================
- http://stackoverflow.com/questions/13228425/write-failed-broken-pipe
- http://raspberrypi.stackexchange.com/questions/26916/broken-pipe-when-ssh-using-mac-os-x
- http://kb.mediatemple.net/questions/1625/Using+an+SSH+Config+File
- http://www.cyberciti.biz/faq/force-ssh-client-to-use-given-private-key-identity-file/
- http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/
- http://docs.rapidminer.com/radoop/installation/cluster-security.html
- http://www.vanemery.com/Linux/XoverSSH/X-over-SSH2.html
- http://linux.about.com/od/commands/l/blcmdl1_ssh.htm
- ======================================================
- To configure SSH over Mac
- ======================================================
- To manage apps over Mac
- http://serverfault.com/questions/194832/how-to-start-stop-restart-launchd-services-from-the-command-line
- http://superuser.com/questions/478035/command-line-ssh-restart-mac-osx-mountain-lion
- https://www.peterborgapps.com/lingon/
- ======================================================
- To add a key
- ======================================================
- ps | grep ssh-agent
- eval ssh-agent $SHELL
- ssh-add /root/.ssh/asanchez75.bitbucket
- ======================================================
- https://confluence.atlassian.com/pages/viewpage.action?pageId=271943168
- Configuring Multiple SSH Identities for GitBash, Mac OSX, & Linux
- Skip to end of metadata
- Attachments:1
- Added by Mary Anthony [Atlassian Technical Writer], last edited by Mary Anthony [Atlassian Technical Writer] on Oct 06, 2012 (view change)
- Go to start of metadata
- Typically, if you are working with multiple accounts and/or multiple machines, you benefit from creating multiple SSH identities. In Mac OSX, GitBash, and Linux you can use the three ssh- commands to create and manage your identities.
- SSH Command
- Purpose
- ssh-keygen Creates key pairs.
- ssh-agent Agent for providing keys to remote servers. The agent holds loaded keys in memory.
- ssh-add Loads a private key into the agent.
- To support multiple SSH identities in Bitbucket, do the following:
- Create multiple identities for Mac OSX, GitBash, and Linux
- My thanks to the codingbadger and to Charles on the Bitbucket team who helped me get my head around this technique. Any errors here are of my own making of course.
- Create multiple identities for Mac OSX, GitBash, and Linux
- You should at this point already have created at least a single default identity. To see if you have a default identity already, list the contents of your .ssh directory. Default identity files appear as a id_encrypt and id_encrypt.pub pair. The encrypt value is either rsa or dsa. Use the ssh-keygen command to create a new identity. In the example below, the identity is named personalid.
- $ ssh-keygen -f ~/.ssh/personalid -C "personalid"
- Generating public/private rsa key pair.
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /Users/manthony/.ssh/personalid.
- Your public key has been saved in /Users/manthony/.ssh/personalid.pub.
- The key fingerprint is:
- 7a:9c:b2:9c:8e:4e:f4:af:de:70:77:b9:52:fd:44:97 personalid
- The key's randomart image is:
- +--[ RSA 2048]----+
- | |
- | |
- | .|
- | Eo|
- | . S . ..|
- | . . o . ... .|
- | . = = ..o o |
- | . o X ... . .|
- | .ooB.o .. |
- +-----------------+
- If you have multiple Bitbucket accounts, you need to generate a new public/private key pair for each account.
- Create a SSH config file
- When you have multiple identity files, create a SSH config file mechanisms to create aliases for your various identities. You can construct a SSH config file using many parameters and different approaches. The format for the alias entries use in this example is:
- Host alias
- HostName bitbucket.org
- IdentityFile ~/.ssh/identity
- To create a config file for two identities (workid and personalid), you would do the following:
- Open a terminal window.
- Edit the ~/.ssh/config file.
- If you don't have a config file, create one.
- Add an alias for each identity combination for example:
- Host workdid
- HostName bitbucket.org
- IdentityFile ~/.ssh/workdid
- Host personalid
- HostName bitbucket.org
- IdentityFile ~/.ssh/personalid
- Close and save the file.
- Now, you can substitute the alias for portions of the repository URL address as illustrated in the following table:
- DVCS Default address Address with alias
- Git
- [email protected]:accountname/reponame.git
- git@alias:accountname/reponame.git
- Mercurial ssh://[email protected]/username/reponame/ ssh://[email protected] /username/reponame/
- There are lots of ways to use SSH aliasing. Another common use case may be the situation where you are using Bitbucket and GitHub on the same machine. The codingbadger suggested the following configuration for that use case:
- # 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
- If you google for "ssh aliases" or "ssh aliasing" you may find examples that suit you needs better.
- Configure compression for Mercurial
- When sending or retrieving data using SSH, Git does compression for you. Mercurial does not automatically do compression. You should enable SSH compression as it can speed up things drastically, in some cases. To enable compression for Mercurial, do the following:
- Open a terminal window.
- Edit the Mercurial global configuration file (~/.hgrc).
- Add the following line to the UI section:
- ssh = ssh -C
- When you are done the file should look similar to the following:
- [ui]
- # Name data to appear in commits
- username = Mary Anthony <[email protected]>
- ssh = ssh -C
- Save and close the file.
- Load each key into the appropriate Bitbucket account
- You load each identities public key into corresponding account. If you have multiple Bitbucket accounts, you load each account with the corresponding public key you created. If you have an account with a repository you access from two identities, you can load two keys into that account – one for each identity. Use the following procedure to load each key into your Bitbucket accounts:
- Open a browser and log into Bitbucket.
- Choose avatar > Manage Account from the application menu.
- The system displays the Account settings page.
- Click SSH keys.
- The SSH Keys page displays. It shows a list of any existing keys. Then, below that, a dialog for labeling and entering a new key.
- Back in your terminal window, copy the contents of your public key file.
- For example, in Linux you can cat the contents.
- cat ~/.ssh/id_rsa.pub
- In Mac OSX the following command copies the output to the clipboard:
- pbcopy < ~/.ssh/id_rsa.pub
- Back in your browser, enter a Label for your new key, for example, Default public key.
- Paste the copied public key into the SSH Key field:
- Press Add key.
- The system adds the key to your account.
- Ensure the ssh-agent is running and all your keys are loaded
- Most modern operating systems (and GitBash) start a ssh-agent running for you. However, it is important you know how to check for a running agent and start one if necessary.
- Open a terminal window and enter the appropriate command for your operating system.
- GitBash
- Mac OSX andLinux
- $ ps | grep ssh-agent
- 5192 1 5192 5192 ? 500 19:23:34 /bin/ssh-agent
- If for some reason the agent isn't running, start it by entering eval ssh-agent at the command line. You should only be running a single instance of ssh-agent. If you have multiple instances running, use the kill PID command to stop each of them. Then, restart a single instance.
- $ ps -e | grep [s]sh-agent
- 9060 ?? 0:00.28 /usr/bin/ssh-agent -l
- If the agent isn't running, start it by hand. The format for starting the command manually is:
- $ eval ssh-agent $SHELL
- $SHELL is the environment variable for your login shell.
- List the currently loaded keys:
- $ ssh-add -l
- 2048 68:ef:d6:1e:4b:3b:a3:52:6f:b0:c3:4b:da:e8:d1:9f /c/Documents and Settings/manthony/.ssh/personalid (RSA)
- If necessary, add your new key to the list:
- $ ssh-add ~/.ssh/workid
- Enter passphrase for /c/Documents and Settings/manthony/.ssh/workid:
- Identity added: /c/Documents and Settings/manthony/.ssh/workid (/c/Documents and Settings/manthony/.ssh/workid)
- List the keys again to verify the add was successful:
- $ ssh-add -l
- 2048 68:ef:d6:1e:4b:3b:a3:52:6f:b0:c3:4b:da:e8:d1:9f /c/Documents and Settings/manthony/.ssh/personalid (RSA)
- 2048 1b:24:fe:75:4d:d2:31:a9:d5:4e:65:60:7c:60:7a:a3 /c/Documents and Settings/manthony/.ssh/workid (RSA)
- Clone a repository using SSH
- To clone a repository with one of multiple SSH identities that you have added to an SSH config, you would log into Bitbucket and do the following:
- Navigate to the repository Overview.
- Display the SSH URL.
- For example, Bitbucket displays its tutorial URL as:
- hg clone ssh://[email protected]/tutorials/tutorials.bitbucket.org
- Open a terminal window on your system.
- Navigate to the directory where you store your repositories.
- Enter the command but substitute your config alias appropriately:
- hg clone ssh://[email protected]/tutorials/tutorials.bitbucket.org
- The system clones the repository for you.
- Change directory to the repository.
- Display the contents of the repository's configuration.
- $ cat .hg/hgrc
- [paths]
- default = ssh://[email protected]/tutorials/tutorials.bitbucket.org
- Notice that the DVCS stored the URL you used for the clone. Now, moving forward for this repository, the DVCS uses the URL that includes the SSH alias.
- Change existing repositories to from HTTPS to SSH (optional)
- You can change existing repository configurations to use a SSH configuration that makes use of your multiple identities. You'll only need to do this for repositories that you have already cloned with HTTPS or for repositories where you want to change an existing SSH specification. For example, if you used SSH to clone a repository in the past and now want to set it up to use another SSH key.
- Git configuration
- Open a terminal window.
- Navigate to the repository configuration file (REPO_INSTALLDIR/.git).
- Open the config file with your favorite editor.
- Locate the url value in the [remote "origin"] section
- [remote "origin"]
- fetch = +refs/heads/*:refs/remotes/origin/*
- url = https://[email protected]/newuserme/bb101repo.git
- In this example, the url is using the HTTPS protocol.
- Change the url value to use the SSH format for your repository.
- When you are done you should see something similar to the following:
- [remote "origin"]
- fetch = +refs/heads/*:refs/remotes/origin/*
- url = git@personalid:newuserme/bb101repo.git
- Mercurial Configuration
- Open a terminal window.
- Navigate to the repository configuration file (REPO_INSTALLDIR/.hg).
- Open the hgrc file with your favorite editor.
- [paths]
- default = https://[email protected]/newuserme/bb101repo
- Change the [paths] default to:
- [paths]
- default = ssh://[email protected]/newuserme/bb101repo
- Save and close the file.
- None
- 10 Comments
- Hide/Show Comments
- User icon: Anonymous
- Apr 02, 2012
- Anonymous
- How do I use the script as described within "Step 5. Update your .bashrc profile file" from Set up SSH for Git in case of automatically loading multiple SSH identities? Ever since I have to enter the appropriate passphrase on every single access to remote repository...
- Permalink
- Reply
- User icon: Anonymous
- Aug 26, 2012
- Anonymous
- I think there is a small error in the default address for mercurial.
- ssh://hg@alias/username/reponame/
- I think it should be:
- ssh://[email protected]/username/reponame/
- Permalink
- Reply
- User icon: manthony
- Aug 26, 2012
- Mary Anthony [Atlassian Technical Writer]
- Thank you for the catch. Fixed.
- Permalink
- Reply
- User icon: Anonymous
- Oct 04, 2012
- Anonymous
- ssh://hg@alias/username/reponame/
- works for me, the current entry does not.
- Permalink
- Reply
- User icon: Anonymous
- Nov 05, 2012
- Anonymous
- Me too
- Permalink
- Reply
- User icon: Anonymous
- Dec 17, 2012
- Anonymous
- That was a mis-correction and should be changed back
- Permalink
- Reply
- User icon: dimpase
- Sep 17, 2012
- Dima Pasechnik
- I beg to differ - this way ssh would not know about the customization in .ssh/config which is associated to the alias.
- Why do you think there was an error?
- Permalink
- Reply
- User icon: Anonymous
- Dec 18, 2012
- Anonymous
- I think it's important to show multiple accounts in the example - this is kinda dropped after step one. I believe this is where the difference of opinion might lie -> it would make sense to clone from an alias if you, indeed, have an alias set up in the .ssh/config file
- Permalink
- Reply
- User icon: Anonymous
- Jan 26, 2013
- Anonymous
- Address with alias git@alias:accountname/reponame.git did not worked for me (osx).
- After googling around i did that in : ~/.ssh/config
- Host somename.bitbucket.org
- HostName bitbucket.org
- User git
- IdentityFile ~/.ssh/keyname
- and used in .git/config:
- [remote "origin"]
- url = ssh://somename.bitbucket.org/myUserName/myRepoName.git
- Permalink
- Reply
- User icon: Anonymous
- Feb 01, 2013
- Anonymous
- The minimal usable format for the SSH config file on the Mac is
- Host bitbucket.org
- IdentityFile ~/.ssh/youridentityfile
- Works fine.lked
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement