Connect to a remote server with SSH
Assuming you don’t have an identity file configured you will be prompted for your password:
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
HostName actual.domain.com
Now you can connect via ssh myuser@myserver [...]
.
To pre-configure a username, add the User
option:
Host myserver
HostName actual.domain.com
User myuser
Now you can connect via ssh myserver [...]
.
To specify an ssh key add the IdentityFile
option:
Host myserver
HostName actual.domain.com
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/id_rsa.pub user@host
Otherwise, you can run something like the following (exclude the mkdir part if the .ssh directory already exists):
cat ~/.ssh/id_rsa.pub | ssh user@host "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/id_rsa.pub
Changing ssh key passphrase
At prompt target existing key file. You will be prompted to enter and confirm the new passphrase.
ssh-keygen -p