Basic Format
ssh [options] user@hostKey Options
-p port
Specifies the port to connect to on the remote host.
-i key_file
Selects a file from which the identity (private key) is read.
-t
Forces pseudo-terminal allocation.
-X
Enables X11 forwarding.
Examples
ssh user@host
Connect to 'host' as 'user'.
ssh -p 2222 user@host
Connect to 'host' at port 2222 as 'user'.
ssh -i key.pem user@host
Connect to 'host' as 'user' using 'key.pem' private key.
ssh -t user@host 'command'
Connect to 'host' as 'user' and run 'command'.
ssh -X user@host
Connect to 'host' as 'user' with X11 forwarding for GUI.
Copying Files with SSH
scp source user@host:destination | Copies 'source' to 'host' at 'destination'. |
|
scp user@host:source destination | Copies 'source' from 'host' to local 'destination'. |
|
scp -r dir user@host:destination | Copies the entire directory 'dir' to 'host' at 'destination'. |
SSH Config File
You can create a config file for ssh as ~/.ssh/config to simplify your ssh commands:
Host myhost HostName host.com User username Port 2222 IdentityFile ~/.ssh/key.pem
Now you can just use 'ssh myhost' instead of the full command.