Connect to a remote server with SSH

Assuming you don't have an identity file configured you will be prompted for your password:

ssh [email protected]

Use -i to specify an ssh key:

ssh [email protected] -i ~/.ssh/my-private-key

Configure SSH

To create an alias for a domain, edit ~/.ssh/config:

Host myserver

Now you can connect via ssh [email protected] [...].

To pre-configure a username, add the User option:

Host myserver
    User myuser

Now you can connect via ssh myserver [...].

To specify an ssh key add the IdentityFile option:

Host myserver
    User myuser
    IdentityFile /home/myName/.ssh/my-private-key

Now you can use ssh myserver instead of ssh myserver -i ~/.ssh/my-private-key.

Generating ssh key pairs

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Adding ssh public key to remote server

If you are running linux you can use:

ssh-copy-id -i ~/.ssh/ [email protected]

Otherwise, you can run something like the following (exclude the mkdir part if the .ssh directory already exists):

cat ~/.ssh/ | ssh [email protected] "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"

Copying public key to clipboard

# if you need to install xclip
sudo apt-get install xclip

# target your public key
xclip -sel clip < ~/.ssh/ 

Changing ssh key passphrase

At prompt target existing key file. You will be prompted to enter and confirm the new passphrase.

ssh-keygen -p