{"id":618,"date":"2022-11-12T02:29:03","date_gmt":"2022-11-12T02:29:03","guid":{"rendered":"https:\/\/formatswap.com\/blog\/?p=618"},"modified":"2023-01-26T23:39:42","modified_gmt":"2023-01-26T23:39:42","slug":"how-to-setup-openssh-with-keys-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/","title":{"rendered":"How to Setup OpenSSH with Keys on Ubuntu 22.04"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"576\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/ssh-keys-tut-1024x576.jpg\" alt=\"ssh key splash\" class=\"wp-image-709\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/ssh-keys-tut-1024x576.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/ssh-keys-tut-300x169.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/ssh-keys-tut-768x432.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/ssh-keys-tut-1536x864.jpg 1536w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/ssh-keys-tut.jpg 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p>In this tutorial you will learn how to setup a SSH server to use a public key pair on Ubuntu. SSH is a secure protocol used for remotely administrating servers. We will be using <a href=\"https:\/\/en.wikipedia.org\/wiki\/OpenSSH\">OpenSSH<\/a> to setup the server. SSH servers are great as they allow you to easily remote into any machine and execute commands. With public key authentication you get robust security. It is generally recommended that all users running an SSH server should enable key based authentication. You also don&#8217;t have to remember passwords when using key based authentication. For this tutorial we will be using Ubuntu 22.04 server, but you should be able to use any Linux operating system. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Generate Key Pair<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"748\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/1-generate-keys-1024x748.jpg\" alt=\"generate key pair\" class=\"wp-image-683\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/1-generate-keys-1024x748.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/1-generate-keys-300x219.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/1-generate-keys-768x561.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/1-generate-keys.jpg 1320w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The first step is to generate a key pair on your client machine. Type &#8220;ssh-keygen&#8221; and press &#8220;Enter&#8221;. If you get an error you may have to install the <a href=\"https:\/\/en.wikipedia.org\/wiki\/OpenSSH\">Openssh<\/a> server as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo apt install openssh-server<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Select Key Save Location<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"735\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/2-confirm-directory-keys-1024x735.jpg\" alt=\"select key save file location\" class=\"wp-image-684\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/2-confirm-directory-keys-1024x735.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/2-confirm-directory-keys-300x215.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/2-confirm-directory-keys-768x551.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/2-confirm-directory-keys.jpg 1324w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Next you will be asked to choose a save location for the key. Press &#8220;Enter&#8221; to use the default, or type a path and filename for the key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Set a Key Password (optional)<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"740\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/3-optional-passphrase-1024x740.jpg\" alt=\"select password\" class=\"wp-image-685\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/3-optional-passphrase-1024x740.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/3-optional-passphrase-300x217.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/3-optional-passphrase-768x555.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/3-optional-passphrase.jpg 1322w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You will then be asked if you want to set a key on the password. This improves security but will require you to enter the password every time you connect to the SSH server. Either type a password or press the &#8220;Enter&#8221; key twice to not use a password.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Key Generated Successfully<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"708\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/4-keygen-success-1024x708.jpg\" alt=\"key generated\" class=\"wp-image-686\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/4-keygen-success-1024x708.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/4-keygen-success-300x207.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/4-keygen-success-768x531.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/4-keygen-success.jpg 1316w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now you will see a message telling you that the key pair has been generated successfully. It will also list the fingerprint and the save location for the key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Copying Public Key<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"746\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/5-copy-key-to-server-1024x746.jpg\" alt=\"copy the public key\" class=\"wp-image-687\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/5-copy-key-to-server-1024x746.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/5-copy-key-to-server-300x219.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/5-copy-key-to-server-768x559.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/5-copy-key-to-server.jpg 1311w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Next we will copy the newly created key to your SSH server. Type in the following command to copy the key.<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>ssh-copy-id username@ssh-server-ipaddress<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Enter the SSH Users Password<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"739\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/6-enter-ssh-pass-1024x739.jpg\" alt=\"optionally select password for key\" class=\"wp-image-688\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/6-enter-ssh-pass-1024x739.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/6-enter-ssh-pass-300x217.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/6-enter-ssh-pass-768x555.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/6-enter-ssh-pass.jpg 1324w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The server will then ask you to type in the password for the SSH user. Additionally if you set up a password on the key pair, you will also be prompted to type that.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Keys Successfully Added<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"731\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/7-key-successfully-added-1024x731.jpg\" alt=\"keys added message\" class=\"wp-image-689\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/7-key-successfully-added-1024x731.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/7-key-successfully-added-300x214.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/7-key-successfully-added-768x548.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/7-key-successfully-added.jpg 1322w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>After typing your credentials you will be shown a screen telling you that the key has been successfully added.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SSH into the Server<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"741\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/8-ssh-into-server-1024x741.jpg\" alt=\"ssh into the server\" class=\"wp-image-690\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/8-ssh-into-server-1024x741.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/8-ssh-into-server-300x217.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/8-ssh-into-server-768x556.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/8-ssh-into-server.jpg 1319w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now that the key has been added to the SSH server we need to connect back to the server. Connect to it using the SSH command as shown above.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Edit the OpenSSH Config File<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"738\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/9-open-sshd-config-1024x738.jpg\" alt=\"edit the openssh config\" class=\"wp-image-691\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/9-open-sshd-config-1024x738.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/9-open-sshd-config-300x216.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/9-open-sshd-config-768x554.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/9-open-sshd-config.jpg 1319w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Once you are connected to the server you will need to edit a file. Open the sshd_config file using the nano text editor.<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo nano \/etc\/ssh\/sshd_config<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Disable Password Authentication<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"742\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/10-set-pass-auth-to-no-1024x742.jpg\" alt=\"disable password authentication\" class=\"wp-image-692\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/10-set-pass-auth-to-no-1024x742.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/10-set-pass-auth-to-no-300x217.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/10-set-pass-auth-to-no-768x556.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/10-set-pass-auth-to-no.jpg 1316w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now that the file is open, use &#8220;Ctrl+W&#8221; to search for the line &#8220;PasswordAuthentication&#8221;. Once you locate the line change it from &#8220;PasswordAuthentication yes&#8221; to &#8220;PasswordAuthentication no&#8221;. This will cause the SSH server to only log you in using your key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Save OpenSSH Config File<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"751\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/11-save-file-1024x751.jpg\" alt=\"save openssh config\" class=\"wp-image-693\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/11-save-file-1024x751.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/11-save-file-300x220.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/11-save-file-768x563.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/11-save-file.jpg 1311w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Next simply press &#8220;Ctrl+x&#8221; then the &#8220;Y&#8221; key to save the config file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Restart OpenSSH Server<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"734\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/12-restart-ssh-1024x734.jpg\" alt=\"restart openssh server\" class=\"wp-image-694\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/12-restart-ssh-1024x734.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/12-restart-ssh-300x215.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/12-restart-ssh-768x551.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/12-restart-ssh.jpg 1312w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Finally we will need to restart the ssh service on the server. Run the following command to complete this action.<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo systemctl restart ssh<\/code><\/pre>\n\n\n\n<p>After the SSH service restarts, you will need to disconnect from the SSH server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Test the SSH Connection<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"716\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/13-test-key-ssh-1024x716.jpg\" alt=\"test ssh connection\" class=\"wp-image-695\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/13-test-key-ssh-1024x716.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/13-test-key-ssh-300x210.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/13-test-key-ssh-768x537.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/13-test-key-ssh.jpg 1323w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now we will test that we are able to login to the SSH server using our key pair. Simply try to reconnect to the SSH server. You will be automatically logged in if you don&#8217;t have a password on the key pair. Else you will need to enter the password you created for the key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">OpenSSH with a Key Pair is Enabled<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"732\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/14-connect-succesful-keys-enabled-1024x732.jpg\" alt=\"successful key ssh \" class=\"wp-image-696\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/14-connect-succesful-keys-enabled-1024x732.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/14-connect-succesful-keys-enabled-300x215.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/14-connect-succesful-keys-enabled-768x549.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/14-connect-succesful-keys-enabled.jpg 1316w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>If you are able to connect to the SSH server then you have successfully setup a key for <a href=\"https:\/\/en.wikipedia.org\/wiki\/OpenSSH\">OpenSSH<\/a>. Remember to keep the key pair in a secure location. Anyone with access to it would be able to login to your server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SFTP Server (optional)<\/h2>\n\n\n\n<p>You can also enable secure file transfer with SFTP using OpenSSH. If you would like to activate the server view our <strong><a href=\"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-an-sftp-server-on-ubuntu-22-04-using-openssh\/\">How to Setup an SFTP Server on Ubuntu 22.04 using OpenSSH<\/a><\/strong> tutorial.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Additional Questions?<\/h2>\n\n\n\n<p>If you have any additional questions or thoughts feel free to comment them below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Resources<\/h2>\n\n\n\n<p>View our list of <a href=\"https:\/\/formatswap.com\/blog\/programming\/the-top-5-programming-languages-to-learn-in-2022\/\" target=\"_blank\" rel=\"noreferrer noopener\">The Top 10 Programming Languages to Learn in 2022<\/a>.<\/p>\n\n\n\n<p>Learn <a href=\"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-install-veracrypt-and-encrypt-a-flash-drive-on-ubuntu-22-04\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Install Ubuntu Server 22.04 [Step by Step]<\/a>.<\/p>\n\n\n\n<p>Click here to learn <a href=\"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-install-mysql-on-ubuntu-server-22-04-lts\/\">How to Install MySQL on Ubuntu Server 22.04 LTS.<\/a><\/p>\n\n\n\n<p>View all of our <a href=\"https:\/\/formatswap.com\/blog\/category\/linux-tutorials\/\" target=\"_blank\" rel=\"noreferrer noopener\">Linux Articles and Tutorials<\/a>.<\/p>\n\n\n\n<p>Learn <a href=\"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-install-and-configure-nginx-ubuntu-20-04\/\">How to install and configure Nginx \u2013 Ubuntu 20.04<\/a>.<\/p>\n\n\n\n<p>View all of our available online tools and converters at <a href=\"https:\/\/formatswap.com\" target=\"_blank\" rel=\"noreferrer noopener\">Formatswap.com<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial you will learn how to setup a SSH server to use a public key pair on Ubuntu. SSH is a secure protocol used for remotely administrating servers. We will be using OpenSSH to setup the server. SSH servers are great as they allow you to easily remote into any machine and execute [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[4],"tags":[8,41,14,31],"class_list":["post-618","post","type-post","status-publish","format-standard","hentry","category-linux-tutorials","tag-linux","tag-openssh","tag-tutorial","tag-ubuntu"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Setup OpenSSH with Keys on Ubuntu 22.04 - Format Swap - Tech Tutorials<\/title>\n<meta name=\"description\" content=\"You will learn how to setup a SSH server to use a public key pair on Ubuntu. This will strongly increase security on your OpenSSH server.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Setup OpenSSH with Keys on Ubuntu 22.04 - Format Swap - Tech Tutorials\" \/>\n<meta property=\"og:description\" content=\"You will learn how to setup a SSH server to use a public key pair on Ubuntu. This will strongly increase security on your OpenSSH server.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/\" \/>\n<meta property=\"og:site_name\" content=\"Format Swap - Tech Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-12T02:29:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-26T23:39:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/ssh-keys-tut-1024x576.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/#\\\/schema\\\/person\\\/3d01ee8e1e4f3718cfcc57eeb8ad6188\"},\"headline\":\"How to Setup OpenSSH with Keys on Ubuntu 22.04\",\"datePublished\":\"2022-11-12T02:29:03+00:00\",\"dateModified\":\"2023-01-26T23:39:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/\"},\"wordCount\":745,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/ssh-keys-tut-1024x576.jpg\",\"keywords\":[\"linux\",\"openssh\",\"tutorial\",\"ubuntu\"],\"articleSection\":[\"Linux Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/\",\"url\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/\",\"name\":\"How to Setup OpenSSH with Keys on Ubuntu 22.04 - Format Swap - Tech Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/ssh-keys-tut-1024x576.jpg\",\"datePublished\":\"2022-11-12T02:29:03+00:00\",\"dateModified\":\"2023-01-26T23:39:42+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/#\\\/schema\\\/person\\\/3d01ee8e1e4f3718cfcc57eeb8ad6188\"},\"description\":\"You will learn how to setup a SSH server to use a public key pair on Ubuntu. This will strongly increase security on your OpenSSH server.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/#primaryimage\",\"url\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/ssh-keys-tut.jpg\",\"contentUrl\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/ssh-keys-tut.jpg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Setup OpenSSH with Keys on Ubuntu 22.04\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/\",\"name\":\"Format Swap - Tech Tutorials\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/#\\\/schema\\\/person\\\/3d01ee8e1e4f3718cfcc57eeb8ad6188\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/55cb3548d8c931eac3f2facbca246c6bde86082f48ca304906d7da2214191b72?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/55cb3548d8c931eac3f2facbca246c6bde86082f48ca304906d7da2214191b72?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/55cb3548d8c931eac3f2facbca246c6bde86082f48ca304906d7da2214191b72?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/formatswap.com\\\/blog\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCsIPLkRPTbbTaT8YX0Dh2-A\"],\"url\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Setup OpenSSH with Keys on Ubuntu 22.04 - Format Swap - Tech Tutorials","description":"You will learn how to setup a SSH server to use a public key pair on Ubuntu. This will strongly increase security on your OpenSSH server.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/","og_locale":"en_US","og_type":"article","og_title":"How to Setup OpenSSH with Keys on Ubuntu 22.04 - Format Swap - Tech Tutorials","og_description":"You will learn how to setup a SSH server to use a public key pair on Ubuntu. This will strongly increase security on your OpenSSH server.","og_url":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/","og_site_name":"Format Swap - Tech Tutorials","article_published_time":"2022-11-12T02:29:03+00:00","article_modified_time":"2023-01-26T23:39:42+00:00","og_image":[{"url":"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/ssh-keys-tut-1024x576.jpg","type":"","width":"","height":""}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/#article","isPartOf":{"@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/"},"author":{"name":"admin","@id":"https:\/\/formatswap.com\/blog\/#\/schema\/person\/3d01ee8e1e4f3718cfcc57eeb8ad6188"},"headline":"How to Setup OpenSSH with Keys on Ubuntu 22.04","datePublished":"2022-11-12T02:29:03+00:00","dateModified":"2023-01-26T23:39:42+00:00","mainEntityOfPage":{"@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/"},"wordCount":745,"commentCount":0,"image":{"@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/#primaryimage"},"thumbnailUrl":"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/ssh-keys-tut-1024x576.jpg","keywords":["linux","openssh","tutorial","ubuntu"],"articleSection":["Linux Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/","url":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/","name":"How to Setup OpenSSH with Keys on Ubuntu 22.04 - Format Swap - Tech Tutorials","isPartOf":{"@id":"https:\/\/formatswap.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/#primaryimage"},"image":{"@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/#primaryimage"},"thumbnailUrl":"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/ssh-keys-tut-1024x576.jpg","datePublished":"2022-11-12T02:29:03+00:00","dateModified":"2023-01-26T23:39:42+00:00","author":{"@id":"https:\/\/formatswap.com\/blog\/#\/schema\/person\/3d01ee8e1e4f3718cfcc57eeb8ad6188"},"description":"You will learn how to setup a SSH server to use a public key pair on Ubuntu. This will strongly increase security on your OpenSSH server.","breadcrumb":{"@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/#primaryimage","url":"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/ssh-keys-tut.jpg","contentUrl":"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2022\/11\/ssh-keys-tut.jpg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-setup-openssh-with-keys-on-ubuntu-22-04\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/formatswap.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Setup OpenSSH with Keys on Ubuntu 22.04"}]},{"@type":"WebSite","@id":"https:\/\/formatswap.com\/blog\/#website","url":"https:\/\/formatswap.com\/blog\/","name":"Format Swap - Tech Tutorials","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/formatswap.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/formatswap.com\/blog\/#\/schema\/person\/3d01ee8e1e4f3718cfcc57eeb8ad6188","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/55cb3548d8c931eac3f2facbca246c6bde86082f48ca304906d7da2214191b72?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/55cb3548d8c931eac3f2facbca246c6bde86082f48ca304906d7da2214191b72?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/55cb3548d8c931eac3f2facbca246c6bde86082f48ca304906d7da2214191b72?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/formatswap.com\/blog","https:\/\/www.youtube.com\/channel\/UCsIPLkRPTbbTaT8YX0Dh2-A"],"url":"https:\/\/formatswap.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/posts\/618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/comments?post=618"}],"version-history":[{"count":4,"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/posts\/618\/revisions"}],"predecessor-version":[{"id":957,"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/posts\/618\/revisions\/957"}],"wp:attachment":[{"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/media?parent=618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/categories?post=618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/tags?post=618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}