Collection of useful SSH commands
Create cryptographically strong SSH key
Create a new pair of public and private SSH keys
ssh-keygen
Next open up your public SSH key and change the last section to a memorable name. The last part is treated as a comment.
code ~/.ssh/id_rsa.pub
Copy SSH key to a server
Copy your public SSH key to a remote server for authentication
ssh-copy-id root@<ip-address>
Next enter the password for the account that you are adding SSH authentication to. After this you should be able to authenticate to the server without providing a password.
SSH into a remote machine
ssh -p <port-number> -i <path-to-ssh-keys> root@<ip-address>
Running a one off command on the remote machine
ssh root@<ip-address> hostname
SSH config
Simplify connections with SSH config files
Add ~/.ssh/config
file
Host foo
HostName 127.0.0.1
User root
IdentityFile ~/.ssh/id_rsa
Port 22
Now you can SSH with ssh foo
and that will use your configured values.