SSH

By Greg Gallardo

SSH

I use SSH all the time for work and my own projects. This post is just a collection of SSH related commands that I find useful.

Basic Usage

Log into a machine as a specific user with ssh.

  ssh username@example.com

Specify a port other than the default (22) with -p.

  ssh username@example.com -p 5555
  ssh ssh://username@example.com:5555

Specify a SSH key with -i followed by the path to the key.

  ssh -i ~/.ssh/my_key  username@example.com

Copy Files

SCP

I occasionally use scp to copy files over the network (but I usually use SFTP)

scp -P 5555   -i ~/.ssh/my_id  <FILE_NAME> username@example.com:/home/username/<FILE_NAME> 

Note:

To copy an entire folder use the -r option

scp -r host:path/directory .

SFTP

sftp lets you interactively copy files to and from a server.

sftp -oPort=5555   -i ~/.ssh/my_id  username@example.com

The basic commands are: