12 January 2011


by mo

To install ssh in ubuntu

$ sudo apt-get install openssh-client openssh-server

To install in cygwin install the openssh package under “net”. You will also need to run “ssh-host-config” after install to run the server.

Then to ssh into your machine use the below command. The standard port is 22, but you should change this. You can either update the config file located at “/etc/ssh/sshd_config” or you can do a port forward on your public facing firewall.

  $ ssh mo@<server> -p <port>

To copy files from a remote machine down to your local machine you can use the scp command.

# copy from a remote machine to my machine:
  $ scp user@ /home/me/Desktop/file.txt

# copy from my machine to a remote machine:
  $ scp /home/me/Desktop/file.txt user@

# copy all file*.txt from a remote machine to my machine (file01.txt, file02.txt, etc.; note the quotation marks:
  $ scp "user@*.txt" /home/me/Desktop/file.txt

# copy a directory from a remote machien to my machine:
  $ scp -r user@ /home/me/Desktop/.


When you need to manage public/private keys for different git repositories on one machine you can use a config file in your ~/.ssh/ directory. Using the config file you can specify which keys to use for specify urls.

For example the following is a sample ssh config file.

Host github.com
  User git
  Hostname github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/github/id_rsa

Host unfuddle.com
  User git
  Hostname unfuddle.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/unfuddle/id_rsa

In some cases you may need to “ssh-add ~./ssh/github/id_rsa” each public key/pair. You may also have to “chmod 600 ~/.ssh/github/*”

To figure out what key is being supplied when cloning a git repo you can ssh to the destination server using the git user. The following command should give you enough information to figure out what’s going on.

  $ ssh -v git@github.com


To mount a remote filesystem.

  $ mkdir ~/godaddy
  $ sshfs -C user@user.com: ~/godaddy
  $ ls ~/godaddy

To unmount

  $ fusermount -u ~/godaddy

mount a remote file system