ssh Posted on January 12, 2011 tools
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@192.168.1.100:/home/remote_user/Desktop/file.txt /home/me/Desktop/file.txt
# copy from my machine to a remote machine:
$ scp /home/me/Desktop/file.txt user@192.168.1.100:/home/remote_user/Desktop/file.txt
# copy all file*.txt from a remote machine to my machine (file01.txt, file02.txt, etc.; note the quotation marks:
$ scp "user@192.168.1.100:/home/remote_user/Desktop/file*.txt" /home/me/Desktop/file.txt
# copy a directory from a remote machien to my machine:
$ scp -r user@192.168.1.100:/home/remote_user/Desktop/files /home/me/Desktop/.
SSH & GIT
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
SSHFS
To mount a remote filesystem.
$ mkdir ~/godaddy
$ sshfs -C user@user.com: ~/godaddy
$ ls ~/godaddy
To unmount
$ fusermount -u ~/godaddy