SSH

Secure Shell (SSH) is a cryptographic network protocol, which enables you to securely communicate, on an unsecured network, between all of your local computers and any remote servers you use, such as GitHub or your website hosting company’s VPS servers.

SSH enables secure remote system administration and file transfer over insecure networks. You can log into a remote server and work on that computer’s command line from your own local computer’s user interface, ie., the keyboard and desktop.

You set SSH up by creating computer generated, private and public keys. The keys are very large strings of numbers and letters that are very difficult to unscramble.

Store your private key in your local development environment and send your public key to a computer you want to connect to. Your public key identifies the computer you want to connect with and your private key encodes and decodes the information you want to send over the connection.

Use ssh-keygen -t rsa to create the keys on your local computer. cd into the directory you want to store the keys (/home/example/.ssh/id_rsa). Example is your user name. You can enter a pass phrase or not. That additional layer of security is a good idea.

Your private key is stored in /home/example/.ssh/id_rsa. Your public key is stored in /home/example/.ssh/id_rsa.pub.

Use ssh-copy-id example@198.50.100.0 (the IP address of your live website). You can also use the command:

cat ~/.ssh/id_rsa.pub | ssh example@198.50.100.0 “mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys”

Check the response, make sure you have the right key and answer yes. If you set a pass phrase, you’ll have to enter it every time you log into this ssh channel.

You can also do this manually by using cat ~/.ssh/id_rsa.pub . You’ll get an output that looks like this:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCqql6MzstZYh1TmWWv11q5O3pISj2ZFl9HgH1JLknLLx44+tXfJ7mIrKNxOOwxIxvcBF8PXSYvobFYEZjGIVCEAjrUzLiIxbyCoxVyle7Q+bqgZ8SeeM8wzytsY+dVGcBxF6N4JS+zVk5eMcV385gG3Y6ON3EG112n6d+SMXY0OEBIcO6x+PnUSGHrSgpBgX7Ks1r7xqFa7heJLLt2wWwkARptX7udSq05paBhcpB0pHtA1Rfz3K2B+ZVIpSDfki9UVKzT8JUmwW6NNzSgxUfQHGwnW7kj4jp4AT0VZk3ADw497M2G/12N0PPB5CnhHf7ovgy6nL1ikrygTKRFmNZISvAcywB9GVqNAVE+ZHDSCuURNsAInVzgYo9xgJDW8wUw2o8U77+xiFxgI5QSZX3Iq7YLMgeksaO4rBJEa54k8m5wEiEE1nUhLuJ0X/vh2xPff6SQ1BL/zkOhvJCACK6Vb15mDOeCSq54Cr7kvS46itMosi/uS66+PujOO+xt/2FWYepz6ZlN70bRly57Q06J+ZJoc9FfBCbCyYH7U/ASsmY095ywPsBo1XQ9PqhnN1/YOorJ068foQDNVpm146mUpILVxmq41Cj55YKHEazXGsdBIbXWhcrRf4G2fJLRcGUr9q8/lERo9oxRm5JFX6TCmj6kmiFqv+Ow9gI0x8GvaQ== example@test

Make sure the ~/.ssh directory exists on your remote server. The mkdir -p ~/.ssh command will create the directory if necessary, or do nothing if it already exists.

Use echo public_key_string >> ~/.ssh/authorized_keys to add the contents of your id_rsa.pub file on your local computer to the end of the authorized_keys file on your remote server, creating it if necessary. Your public_key_string is everything between ssh-rsa and example@test in the output from the cat ~/.ssh/id_rsa.pub command.

Git and SSH enable you to record the same experience on all of your local development environments and your remote servers.

First create a set of keys. Store the private key in your computer, then send a copy of the public key to your hosting company.

Get familiar with setting up and using virtual environments, containerization, Git and SSH. Each one is a complex tool that you will be using a lot, from now on.

Sources

digitalocean.com/community/tutorials/how-to-set-up-ssh-keys–2