{"id":22206,"date":"2023-10-01T16:56:48","date_gmt":"2023-10-01T16:56:48","guid":{"rendered":"https:\/\/linuxways.net\/?p=22206"},"modified":"2023-10-01T16:57:04","modified_gmt":"2023-10-01T16:57:04","slug":"how-to-generate-ssh-key-with-ssh-keygen-in-linux-ubuntu","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-generate-ssh-key-with-ssh-keygen-in-linux-ubuntu\/","title":{"rendered":"How to Generate SSH Key with ssh-keygen in Linux\/Ubuntu?"},"content":{"rendered":"<p><strong>SSH (Secure Shell)<\/strong> enables users to perform certain tasks, like file transfer, port forwarding, tunnel creation, configuring remote servers, etc. remotely over a secure connection. SSH client is pre-installed in Linux systems. SSH offers two password authentication methods, <strong>password authentication<\/strong> and <strong>public key-based authentication (SSH Keys)<\/strong>. Among these techniques, public key-based authentication enables a higher level of security as compared to longer passwords as it is backed by <strong>ciphers<\/strong>.<\/p>\n<p>This article will demonstrate how to generate an SSH key with <strong>ssh-keygen<\/strong> in Linux\/Ubuntu 22.04 LTS. This article will discuss:<\/p>\n<ul>\n<li>How to Generate\/Create SSH Key in Linux\/Ubuntu?<\/li>\n<li>How to Generate\/Create SSH Keys of Different Types and Sizes?<\/li>\n<li>How to Log in\/Connect to a Remote Server via an SSH Key?<\/li>\n<li>How to Disable SSH Password Authentication?<\/li>\n<\/ul>\n<h2><a id=\"post-22206-_y60uj1mbl3sr\"><\/a>How to Generate\/Create SSH Key with ssh-keygen in Linux\/Ubuntu?<\/h2>\n<p>The following steps are performed in order to generate an SSH keypair:<\/p>\n<h3><a id=\"post-22206-_bje41dqkvc5e\"><\/a>Step 1: Verify if the SSH Key Pair Exists<\/h3>\n<p>Before starting the SSH key generation process, a user can check if any SSH keys already exist in the system as the keys are overwritten if SSH keys are already present in the system. A user can run the following command to verify if SSH keys exist in the system:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span> ~<span class=\"sy0\">\/<\/span>.ssh<span class=\"sy0\">\/<\/span>id_<span class=\"sy0\">*<\/span>.pub<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"185\" class=\"wp-image-22217\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-1.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-1-300x27.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-1-1024x93.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-1-768x69.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-1-1536x139.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>It can be observed from the above image, that there is no SSH key in the system.<\/p>\n<h3><a id=\"post-22206-_abpscobwpqp5\"><\/a>Step 2: Generation of SSH Key Pair<\/h3>\n<p>SSH key pair is generated by executing the following command<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ssh-keygen<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1097\" class=\"wp-image-22224\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-2.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-2-300x161.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-2-1024x549.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-2-768x411.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-2-1536x823.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The user is then prompted to enter the file location to save the keys and a passphrase, after which an SSH keypair is generated with default parameters, i.e., 3072 bits with RSA type. The keys are saved in the <strong>\/home\/linuxuser\/.ssh <\/strong>directory by default.<\/p>\n<h3><a id=\"post-22206-_9p2298cc4rbh\"><\/a>Step 3: Verification of SSH Key Generation<\/h3>\n<p>To verify that keys are generated, the following command is executed:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span> ~<span class=\"sy0\">\/<\/span>.ssh<span class=\"sy0\">\/<\/span>id_<span class=\"sy0\">*<\/span>.pub<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"154\" class=\"wp-image-22226\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-3.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-3-300x23.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-3-1024x77.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-3-768x58.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-3-1536x116.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be verified that the ssh key is generated. The generated keys can be viewed by navigating to the \u201c\/home\/linuxuser\/.ssh\u201d directory using the <strong>cd <\/strong>command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw3\">cd<\/span> <span class=\"sy0\">\/<\/span>home<span class=\"sy0\">\/<\/span>linuxuser<span class=\"sy0\">\/<\/span>.ssh<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"193\" class=\"wp-image-22231\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-4.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-4-300x28.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-4-1024x97.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-4-768x72.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-4-1536x145.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be seen that public and private keys are generated successfully, i.e., <strong>id_rsa.pub<\/strong> and <strong>id_rsa<\/strong>. These keys can be viewed via the <strong>cat <\/strong>command.<\/p>\n<p>To view the public key run the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">cat<\/span> id_rsa.pub<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"403\" class=\"wp-image-22246\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-5.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-5-300x59.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-5-1024x202.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-5-768x151.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-5-1536x302.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>Similarly, the private key can be viewed by executing the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">cat<\/span> id_rsa<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2008\" height=\"1112\" class=\"wp-image-22276\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-6.png 2008w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-6-300x166.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-6-1024x567.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-6-768x425.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-6-1536x851.png 1536w\" sizes=\"auto, (max-width: 2008px) 100vw, 2008px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1155\" class=\"wp-image-22311\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-7.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-7-300x169.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-7-1024x578.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-7-768x433.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-7-1536x866.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<h1><\/h1>\n<h2><a id=\"post-22206-_fcrgxfhjj6jw\"><\/a>How to Generate\/Create SSH Key of Different Types and Sizes?<\/h2>\n<p><strong>ssh-keygen <\/strong>generates a key of RSA type and 3072 bits by default, but a user can modify these parameters by using <strong>type (-t) <\/strong>and<strong> size (-b)<\/strong> flags followed by the <strong>ssh-keygen <\/strong>command<strong>.<\/strong> Three types of keys can be generated:<\/p>\n<ul>\n<li><strong>RSA (Rivest Shamir Adleman)<\/strong>: RSA encrypts and decrypts using separate but mathematical-related keys. It uses key sizes of 2048 and 3072 bits.<\/li>\n<li><strong>DSA (Digital Signature Algorithm)<\/strong>: DSA is faster than RSA. DSA mostly uses a key size of 1024 bits.<\/li>\n<li><strong>ECDSA (Elliptic Curves Digital Signature Algorithm)<\/strong>: ECDSA is more secure and faster than DSA and RSA. Additionally, ECDSA utilizes lower bandwidth and achieves a higher level of security by using a smaller key size i.e., 256, 384, and 521 bits.<\/li>\n<\/ul>\n<p>The following command is used to generate a 384-bit key of type ECDSA:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ssh-keygen<\/span> <span class=\"re5\">-t<\/span> ecdsa <span class=\"re5\">-b<\/span> <span class=\"nu0\">384<\/span><\/div><\/div>\n<p>Where:<\/p>\n<ul>\n<li>t: type, for example, RSA, DSA, ECDSA.<\/li>\n<li>b: bits (256-bit, 384-bit, or 521-bit)<\/li>\n<\/ul>\n<h1><a id=\"post-22206-_ku16m7x6a0d5\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1255\" class=\"wp-image-22321\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-8.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-8-300x184.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-8-1024x628.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-8-768x471.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-8-1536x941.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/h1>\n<p>The user is then prompted to enter the file location to save the keys and a passphrase after which an SSH key pair is then generated of type ECDSA and size 384.<\/p>\n<p>To verify that keys are generated, the following command is executed:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span> ~<span class=\"sy0\">\/<\/span>.ssh<span class=\"sy0\">\/<\/span>id_<span class=\"sy0\">*<\/span>.pub<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"211\" class=\"wp-image-22325\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-9.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-9-300x31.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-9-1024x106.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-9-768x79.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-9-1536x158.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be verified that the SSH key: <strong>id_ecdsa.pub<\/strong> is generated.<\/p>\n<h2><a id=\"post-22206-_ccg8b94ctq23\"><\/a>How to Log in to a Remote Server via SSH Key?<\/h2>\n<p>A user can log in to a remote server with the generated SSH keys by the following steps:<\/p>\n<h3><a id=\"post-22206-_875pnew0f5yq\"><\/a>Step 1: Copy the Public Key to the Ubuntu Remote Server.<\/h3>\n<p><strong>OpenSSH<\/strong> is a connectivity tool that enables secure encryption for file transfer and remote log-in. The following command is used to install Open SSH<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> apt <span class=\"kw2\">install<\/span> openssh-server<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"645\" class=\"wp-image-22339\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-10.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-10-300x94.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-10-1024x323.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-10-768x242.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-10-1536x484.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>Press <strong>Y<\/strong> to continue with the installation. It will take a few seconds for the Open SSH installation to be completed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"760\" class=\"wp-image-22344\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-11.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-11.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-11-300x111.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-11-1024x380.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-11-768x285.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-11-1536x570.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The status of SSH services can be checked by:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> service <span class=\"kw2\">ssh<\/span> status<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"820\" class=\"wp-image-22353\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-12.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-12.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-12-300x120.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-12-1024x410.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-12-768x308.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-12-1536x615.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be seen that the ssh service is active. Next, the earlier generated public key is copied to the remote server by executing the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span>ssh-copy-id linuxuser<span class=\"sy0\">@<\/span>ubuntu<\/div><\/div>\n<p>Where:<\/p>\n<ul>\n<li>ssh-copy-id: command line tool to copy SSH key to the server.<\/li>\n<li>linuxuser: User Name.<\/li>\n<li>Ubuntu: Remote Server IP or Hostname.<\/li>\n<\/ul>\n<p>From the above command, it can be verified that the public key is added to the remote server.<\/p>\n<h2><\/h2>\n<h3><a id=\"post-22206-_a9mocmkdlguj\"><\/a>Step 2: Log-In\/Connect to a Remote Server with SSH Key<\/h3>\n<p>A user can log in to a remote server via <strong>ssh command<\/strong> by executing the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ssh<\/span> linuxuser<span class=\"sy0\">@<\/span>ubuntu<\/div><\/div>\n<p>Where:<\/p>\n<ul>\n<li>linuxuser: User Name.<\/li>\n<li>ubuntu: Remote Server IP or Hostname.<\/li>\n<\/ul>\n<p>The user is then prompted to enter the passphrase for the private key that was selected at the time of SSH key generation:<\/p>\n<h1><\/h1>\n<p>Enter the passphrase and press <strong>Unlock <\/strong>to log in to a remote server:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"690\" class=\"wp-image-22371\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-15.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-15.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-15-300x101.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-15-1024x345.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-15-768x259.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-15-1536x518.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be seen that the login to a remote server is successful.<\/p>\n<h2><a id=\"post-22206-_nrm92bhs8l7b\"><\/a>How to Disable SSH Password Authentication?<\/h2>\n<p>An extra layer of security can be enabled by disabling the SSH password authentication. In order to disable SSH password authentication, a user can follow the below steps:<\/p>\n<ul>\n<li>Log in to the remote server with sudo privileges and modify the SSH configuration file, i.e., <strong>sshd_config<\/strong> by executing the following command:<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">nano<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>ssh<span class=\"sy0\">\/<\/span>sshd_config<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"960\" class=\"wp-image-22374\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-16.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-16.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-16-300x141.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-16-1024x480.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-16-768x360.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-16-1536x720.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<ul>\n<li>Uncomment the line containing \u201cpasswordauthentication yes\u201d.<\/li>\n<li>Replace yes to no as shown below:<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"960\" class=\"wp-image-22382\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-17.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-17.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-17-300x141.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-17-1024x480.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-17-768x360.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-17-1536x720.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<ul>\n<li>Save and exit the file by pressing [<strong>Ctrl+O<\/strong>] and [<strong>Ctrl+X<\/strong>].<\/li>\n<li>Restart ssh by executing the following command:<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> systemctl restart <span class=\"kw2\">ssh<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"103\" class=\"wp-image-22387\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-18.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-18.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-18-300x15.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-18-1024x52.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-18-768x39.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-18-1536x77.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<ul>\n<li>Verify the status of SSH to ensure that SSH is active and running.<\/li>\n<\/ul>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> systemctl status <span class=\"kw2\">ssh<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"893\" class=\"wp-image-22388\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-19.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-19.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-19-300x131.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-19-1024x447.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-19-768x335.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22206-19-1536x670.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The above image verifies that the SSH password authentication is disabled on the server.<\/p>\n<h2><a id=\"post-22206-_k4r3ojha6hv3\"><\/a>Conclusion<\/h2>\n<p>An SSH key pair is generated by the \u201c<strong>ssh-keygen<\/strong>\u201d command. Additionally, the key type and size can be selected by \u201c<strong>-t\u201d <\/strong>and \u201c<strong>-b<\/strong>\u201d flags respectively. This article demonstrated how to generate an SSH key with ssh-keygen in Linux\/Ubuntu 22.04 LTS. Additionally, logging in on a Ubuntu remote server with SSH public key and disabling password-based authentication is also discussed in this article.<\/p>","protected":false},"excerpt":{"rendered":"<p>An SSH keypair is generated by the \u201cssh-keygen\u201d command. Additionally, the key type and size can be selected by \u201c-t\u201d and \u201c-b\u201d flags respectively.<\/p>","protected":false},"author":110,"featured_media":22418,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049,2],"tags":[],"class_list":["post-22206","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=22206"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22206\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/22418"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=22206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=22206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=22206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}