![]() You now have a public and private key that you can use to authenticate. The next step is to place the public key on your server so that you can use SSH-key-based authentication to log in. Step 2 - Copying the Public Key to Your Ubuntu Server The quickest way to copy your public key to the Ubuntu host is to use a utility called ssh-copy-id. Due to its simplicity, this method is highly recommended if available. If you do not have ssh-copy-id available to you on your client machine, you may use one of the two alternate methods provided in this section (copying via password-based SSH, or manually copying the key). The ssh-copy-id tool is included by default in many operating systems, so you may have it available on your local system. For this method to work, you must already have password-based SSH access to your server. To use the utility, you specify the remote host that you would like to connect to, and the user account that you have password-based SSH access to. ![]() ![]() This is the account to which your public SSH key will be copied. Now try logging into the machine, with: "ssh ' 203.0.113.1'"Īnd check to make sure that only the key(s) you wanted were added.Īt this point, your id_rsa.pub key has been uploaded to the remote account. If you do not have ssh-copy-id available, but you have password-based SSH access to an account on your server, you can upload your keys using a conventional SSH method. We can do this by using the cat command to read the contents of the public SSH key on our local computer and piping that through an SSH connection to the remote server. On the other side, we can make sure that the ~/.ssh directory exists and has the correct permissions under the account we’re using. We can then output the content we piped over into a file called authorized_keys within this directory. We’ll use the > redirect symbol to append the content instead of overwriting it. Cat ~/.ssh/id_rsa.pub | ssh remote_host "mkdir -p ~/.ssh & touch ~/.ssh/authorized_keys & chmod -R go= ~/.ssh & cat > ~/.ssh/authorized_keys".This will let us add keys without destroying previously added keys.
0 Comments
Leave a Reply. |