njl.io

ssh

Connecting to a server via ssh using the current user.

ssh example.ssh.com

Connecting to a server via ssh using a specific username.

ssh username@example.ssh.com

or

ssh -l username example.ssh.com

Connecting to a port other than 22 with ssh.

You can change the port by using the -p flag with ssh.

ssh username@example.ssh.com -p 8022

If the port you’ve used is not open to ssh you may see an error like this:

ssh: connect to host xx.xx.xxx.xx port 8022: Connection refused.

Using ssh to copy a file from the remote host.

This will copy from the username’s home directory to the current working directory

scp username@example.ssh.com:foo.txt foo.txt

The following copies from a specific path starting at the home directory on the remote machine to the current working directory.

scp username@example.ssh.com:specific-dir/foo.txt foo.txt

The following copies from a specific absoute path on the remote machine to a specific absolute path on the machine executing the command.

scp username@example.ssh.com:/usr/local/username/specific-dir/foo.txt /etc/foo.txt