{"id":635,"date":"2021-02-26T22:43:06","date_gmt":"2021-02-26T22:43:06","guid":{"rendered":"http:\/\/mastercom.es\/?p=635"},"modified":"2021-02-26T23:10:57","modified_gmt":"2021-02-26T23:10:57","slug":"how-to-set-up-ssh-keys-on-a-linux","status":"publish","type":"post","link":"http:\/\/mastercom.es\/es\/how-to-set-up-ssh-keys-on-a-linux\/","title":{"rendered":"How To Set up SSH Keys on a Linux"},"content":{"rendered":"\n[et_pb_section fb_built=\u00bb1&#8243; _builder_version=\u00bb4.9.0&#8243; _module_preset=\u00bbdefault\u00bb][et_pb_row _builder_version=\u00bb4.9.0&#8243; _module_preset=\u00bbdefault\u00bb][et_pb_column _builder_version=\u00bb4.9.0&#8243; _module_preset=\u00bbdefault\u00bb type=\u00bb4_4&#8243;][et_pb_text _builder_version=\u00bb4.9.0&#8243; _module_preset=\u00bbdefault\u00bb hover_enabled=\u00bb0&#8243; sticky_enabled=\u00bb0&#8243;]<p><span style=\"font-size: 14px;\">This page explains a public key and shows you how to set up SSH keys on a Linux or Unix-like server. I am assuming that you are using Linux or Unix-like server and client with the following software:<\/span><span style=\"font-size: 14px;\">\u00a0<\/span><\/p>\n<ul>\n<li>OpenSSH SSHD server<\/li>\n<li>OpenSSH ssh client and friends on Linux (Ubuntu, Debian, {Free,Open,Net}BSD, RHEL, CentOS, MacOS\/OSX, AIX, HP-UX and co).<\/li>\n<\/ul>\n<h2>What is a public key authentication?<\/h2>\n<p>OpenSSH server supports various authentication schema. The two most popular are as follows:<\/p>\n<ol>\n<li>Passwords based authentication<\/li>\n<li>Public key based authentication. It is an alternative security method to using passwords. This method is recommended on a VPS, cloud, dedicated or even home based server.<\/li>\n<\/ol>\n<h2>How to set up SSH keys<\/h2>\n<p>Steps to setup secure ssh keys:<\/p>\n<ol>\n<li>Create the ssh key pair using<span>\u00a0<\/span><kbd><strong>ssh-keygen<\/strong><\/kbd><span>\u00a0<\/span>command.<\/li>\n<li>Copy and install the public ssh key using<span>\u00a0<\/span><kbd><strong>ssh-copy-id<\/strong><\/kbd><span>\u00a0<\/span>command on a Linux or Unix server.<\/li>\n<li>Add yourself to sudo or wheel group admin account.<\/li>\n<li>Disable the password login for root account.<\/li>\n<li>Test your password less ssh keys login using<span>\u00a0<\/span><kbd><strong>ssh user@server-nam<\/strong>e<\/kbd><span>\u00a0<\/span>command.<\/li>\n<\/ol>\n<p>Let us see all steps in details.<\/p>\n<h2>How do I set up public key authentication?<\/h2>\n<p>You must generate both a public and a private key pair. For example:<\/p>\n<div id=\"attachment_145671\" class=\"wp-caption aligncenter amp-wp-cb4b39f\" data-amp-original-style=\"width: 609px\">\n<p><amp-img aria-describedby=\"caption-attachment-145671\" src=\"https:\/\/www.cyberciti.biz\/media\/new\/faq\/2014\/03\/ssh-welcome-setup.png\" alt=\"Fig.01: Our sample ssh set up keys\" width=\"599\" height=\"347\" class=\"size-full wp-image-145671 amp-wp-enforced-sizes i-amphtml-layout-intrinsic i-amphtml-layout-size-defined i-amphtml-element i-amphtml-built i-amphtml-layout\" srcset=\"https:\/\/www.cyberciti.biz\/media\/new\/faq\/2014\/03\/ssh-welcome-setup.png 599w, https:\/\/www.cyberciti.biz\/media\/new\/faq\/2014\/03\/ssh-welcome-setup-300x174.png 300w\" sizes=\"(max-width: 599px) 100vw, 599px\" layout=\"intrinsic\" disable-inline-width=\"\" i-amphtml-layout=\"intrinsic\" i-amphtml-auto-lightbox-visited=\"\"><img decoding=\"async\" alt=\"Fig.01: Our sample ssh set up keys\" aria-describedby=\"caption-attachment-145671\" sizes=\"(max-width: 599px) 100vw, 599px\" srcset=\"https:\/\/www.cyberciti.biz\/media\/new\/faq\/2014\/03\/ssh-welcome-setup.png 599w, https:\/\/www.cyberciti.biz\/media\/new\/faq\/2014\/03\/ssh-welcome-setup-300x174.png 300w\" src=\"https:\/\/www.cyberciti.biz\/media\/new\/faq\/2014\/03\/ssh-welcome-setup.png\" class=\"i-amphtml-fill-content i-amphtml-replaced-content\" \/><\/amp-img><\/p>\n<p id=\"caption-attachment-145671\" class=\"wp-caption-text\">Fig.01: Our sample setup<\/p>\n<\/div>\n<p><span>Where,<\/span><\/p>\n<ul>\n<li>server1.cyberciti.biz \u2013 You store your public key on the remote hosts and you have an accounts on this Linux\/Unix based server.<\/li>\n<li>client1.cyberciti.biz \u2013 Your private key stays on the desktop\/laptop\/ computer (or local server) you use to connect to server1.cyberciti.biz server. Do not share or give your private file to anyone.<\/li>\n<\/ul>\n<p>In public key based method you can log into remote hosts and server, and transfer files to them, without using your account passwords. Feel free to replace server1.cyberciti.biz and client1.cyberciti.biz names with your actual setup. Enough talk, let\u2019s set up public key authentication. Open the Terminal and type following commands if .ssh directory does not exists:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"bash\">\n<pre class=\"de1\"><span class=\"kw2\">mkdir<\/span> <span class=\"re5\">-p<\/span> <span class=\"re1\">$HOME<\/span><span class=\"sy0\">\/<\/span>.ssh\n<span class=\"kw2\">chmod<\/span> 0700 <span class=\"re1\">$HOME<\/span><span class=\"sy0\">\/<\/span>.ssh<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h2>1: Create the key pair<\/h2>\n<p>On the computer (such as client1.cyberciti.biz), generate a key pair for the protocol.<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"bash\">\n<pre class=\"de1\"><span class=\"kw2\">ssh-keygen<\/span> <span class=\"re5\">-t<\/span> rsa<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Sample outputs:<\/p>\n<pre>Generating public\/private rsa key pair.\nEnter file in which to save the key (\/Users\/vivek\/.ssh\/id_rsa): \nEnter passphrase (empty for no passphrase): \nEnter same passphrase again: \nYour identification has been saved in \/Users\/vivek\/.ssh\/id_rsa.\nYour public key has been saved in \/Users\/vivek\/.ssh\/id_rsa.pub.\nThe key fingerprint is:\n80:5f:25:7c:f4:90:aa:e1:f4:a0:01:43:4e:e8:bc:f5 vivek@desktop01\nThe key's randomart image is:\n+--[ RSA 2048]----+\n| oo    ...+.     |\n|.oo  .  .ooo     |\n|o .o. . .o  .    |\n| o ...+o.        |\n|  o .=.=S        |\n| .  .Eo .        |\n|                 |\n|                 |\n|                 |\n+-----------------+\n<\/pre>\n<p>You need to set the Key Pair location and name. I recommend you use the default location if you do not yet have another key there, for example: $HOME\/.ssh\/id_rsa. You will be prompted to supply a passphrase (password) for your private key. I suggest that you setup a passphrase when prompted. You should see two new files in $HOME\/.ssh\/ directory:<\/p>\n<ol>\n<li><kbd><span data-amp-original-style=\"color: rgb(255, 0, 0);\" class=\"amp-wp-dc22899\">$HOME\/.ssh\/id_rsa<\/span><\/kbd>\u2013 contains your private key.<\/li>\n<li><kbd><span data-amp-original-style=\"color: rgb(0, 153, 0);\" class=\"amp-wp-981e973\">$HOME\/.ssh\/id_rsa.pub<\/span><\/kbd><span>\u00a0<\/span>\u2013 contain your public key.<\/li>\n<\/ol>\n<h3><span data-amp-original-style=\"color: rgb(102, 102, 204);\" class=\"amp-wp-a1f9c2e\">Optional syntax for advance users<\/span><\/h3>\n<p>The following syntax specifies the 4096 of bits in the RSA key to creation (default 2048):<br \/><code>$ ssh-keygen -t rsa -b 4096 -f ~\/.ssh\/vps-cloud.web-server.key -C \"My web-server key\"<\/code><br \/>Where,<\/p>\n<ul>\n<li><kbd><strong>-t rsa<\/strong><\/kbd><span>\u00a0<\/span>: Specifies the type of key to create. The possible values are \u201crsa1\u201d for protocol version 1 and \u201cdsa\u201d, \u201cecdsa\u201d, \u201ced25519\u201d, or \u201crsa\u201d for protocol version 2.<\/li>\n<li><kbd><strong>-b 4096<\/strong><\/kbd><span>\u00a0<\/span>: Specifies the number of bits in the key to create<\/li>\n<li><kbd><strong>-f ~\/.ssh\/vps-cloud.web-server.key<\/strong><\/kbd><span>\u00a0<\/span>: Specifies the filename of the key file.<\/li>\n<li><kbd><strong>-C \"My web-server key\"<\/strong><\/kbd><span>\u00a0<\/span>: Set a new comment.<\/li>\n<\/ul>\n<h2>2: Install the public key in remote server<\/h2>\n<p>Use scp or ssh-copy-id command to copy your public key file (e.g., $HOME\/.ssh\/id_rsa.pub) to your account on the remote server\/host (e.g., nixcraft@server1.cyberciti.biz). To do so, enter the following command on your client1.cyberciti.biz:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"bash\">\n<pre class=\"de1\">ssh-copy-id <span class=\"re5\">-i<\/span> <span class=\"re1\">$HOME<\/span><span class=\"sy0\">\/<\/span>.ssh<span class=\"sy0\">\/<\/span>id_rsa.pub user<span class=\"sy0\">@<\/span>server1.cyberciti.biz<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>OR just copy the public key in remote server as authorized_keys in ~\/.ssh\/ directory:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"bash\">\n<pre class=\"de1\"><span class=\"kw2\">scp<\/span> <span class=\"re1\">$HOME<\/span><span class=\"sy0\">\/<\/span>.ssh<span class=\"sy0\">\/<\/span>id_rsa.pub user<span class=\"sy0\">@<\/span>server1.cyberciti.biz:~<span class=\"sy0\">\/<\/span>.ssh<span class=\"sy0\">\/<\/span>authorized_keys<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h3>A note about appending the public key in remote server<\/h3>\n<p>On some system<span>\u00a0<\/span><kbd>ssh-copy-id<\/kbd><span>\u00a0<\/span>command may not be installed, so use the following commands (when prompted provide the password for remote user account called vivek) to install and append the public key:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"bash\">\n<pre class=\"de1\"><span class=\"co0\">## First create .ssh directory on server ##<\/span>\n<span class=\"kw2\">ssh<\/span> vivek<span class=\"sy0\">@<\/span>server1.cyberciti.biz <span class=\"st0\">\"umask 077; test -d .ssh || mkdir .ssh\"<\/span>\n\u00a0\n<span class=\"co0\">## cat local id.rsa.pub file and pipe over ssh to append the public key in remote server ##<\/span>\n<span class=\"kw2\">cat<\/span> <span class=\"re1\">$HOME<\/span><span class=\"sy0\">\/<\/span>.ssh<span class=\"sy0\">\/<\/span>id_rsa.pub <span class=\"sy0\">|<\/span> <span class=\"kw2\">ssh<\/span> vivek<span class=\"sy0\">@<\/span>server1.cyberciti.biz <span class=\"st0\">\"cat &gt;&gt; .ssh\/authorized_keys\"<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h2>3: Test it (type command on client1.cyberciti.biz)<\/h2>\n<p>The syntax is as follows for the ssh command:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"bash\">\n<pre class=\"de1\"><span class=\"kw2\">ssh<\/span> user<span class=\"sy0\">@<\/span>server1.cyberciti.biz\n<span class=\"kw2\">ssh<\/span> user<span class=\"sy0\">@<\/span>your-server-ip-address\n<span class=\"kw2\">ssh<\/span> <span class=\"re5\">-i<\/span> ~<span class=\"sy0\">\/<\/span>.ssh<span class=\"sy0\">\/<\/span>your-key user<span class=\"sy0\">@<\/span>your-server-ip-address<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Or copy a text file called foo.txt:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"bash\">\n<pre class=\"de1\"><span class=\"kw2\">scp<\/span> foo.txt user<span class=\"sy0\">@<\/span>server1.cyberciti.biz:<span class=\"sy0\">\/<\/span>tmp<span class=\"sy0\">\/<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>You will be prompted for a passphrase. To get rid of passphrase whenever you log in the remote host, try ssh-agent and ssh-add commands.<\/p>\n<h3>What are ssh-agent and ssh-add, and how do I use them?<\/h3>\n<p>To get rid of a passphrase for the current session, add a passphrase to ssh-agent and you will not be prompted for it when using ssh or scp\/sftp\/rsync to connect to hosts with your public key. The syntax is as follows:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"bash\">\n<pre class=\"de1\"><span class=\"kw3\">eval<\/span> $<span class=\"br0\">(<\/span><span class=\"kw2\">ssh-agent<\/span><span class=\"br0\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Type the<span>\u00a0<\/span><kbd>ssh-add<\/kbd><span>\u00a0<\/span>command to prompt the user for a private key passphrase and adds it to the list maintained by ssh-agent command:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"bash\">\n<pre class=\"de1\"><span class=\"kw2\">ssh-add<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Enter your private key passphrase. Now try again to log into user@server1.cyberciti.biz and you will not be prompted for a password:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"bash\">\n<pre class=\"de1\"><span class=\"kw2\">ssh<\/span> user<span class=\"sy0\">@<\/span>server1.cyberciti.biz<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>One can list public key parameters of all identities with the<span>\u00a0<\/span><kbd>-L<\/kbd><span>\u00a0<\/span>option:<br \/><code>ssh-add -L<\/code><br \/>Deleting all private keys from the ssh-agent can be done with the<span>\u00a0<\/span><kbd>-D<\/kbd><span>\u00a0<\/span>option as follows:<br \/><code>ssh-add -D<\/code><br \/>When you log out kill the ssh agent, run:<br \/><code>kill $SSH_AGENT_PID<\/code><br \/>You can also add something like the below to your shell startup to kill ssh-agent at logout:<br \/><code>trap \"kill $SSH_AGENT_PID\" 0<\/code><\/p>\n<h2>4: Disable the password based login on a server<\/h2>\n<p>Login to your server, type:<\/p>\n<pre>## client commands ##\neval $(ssh-agent)\nssh-add\nssh user@server1.cyberciti.biz\n<\/pre>\n<p>Edit \/etc\/ssh\/sshd_config on server1.cyberciti.biz using a text editor such as nano or vim:<\/p>\n<p class=\"alert\"><strong>Warning<\/strong>: Make sure you add yourself to sudoers files. Otherwise you will not able to login as root later on. See \u201c<a href=\"https:\/\/www.cyberciti.biz\/faq\/how-to-add-delete-grant-sudo-privileges-to-users-on-freebsd-unix-server\/\">How To Add, Delete, and Grant Sudo Privileges to Users on a FreeBSD Server<\/a>\u201d for more info.<\/p>\n<p><code>$ sudo vim \/etc\/ssh\/sshd_config<\/code><br \/>OR<span>\u00a0<\/span><a href=\"https:\/\/www.cyberciti.biz\/faq\/linux-unix-command-open-file-linenumber-function\/\">directly jump to PermitRootLogin line<\/a><span>\u00a0<\/span>using a vim text editor:<br \/><code>$ sudo vim +\/PermitRootLogin \/etc\/ssh\/sshd_config<\/code><br \/>Find PermitRootLogin and set it as follows:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"ini\">\n<pre class=\"de1\">PermitRootLogin no<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Save and close the file. I am<span>\u00a0<\/span><a href=\"https:\/\/www.cyberciti.biz\/faq\/how-to-create-a-sudo-user-on-ubuntu-linux-server\/\">going to add a user named vivek to sudoers on Ubuntu Linux<\/a>:<br \/><code># adduser vivek<\/code><br \/>Finally,<span>\u00a0<\/span><a href=\"https:\/\/www.cyberciti.biz\/faq\/howto-restart-ssh\/\">reload\/restart the sshd server<\/a>, type command as per your Linux\/Unix version:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"bash\">\n<pre class=\"de1\"><span class=\"co0\">## CentOS\/RHEL\/Fedora (older version) Linux server reload sshd ##<\/span>\n<span class=\"kw2\">sudo<\/span> service sshd reload\n\u00a0\n<span class=\"co0\">## CentOS\/RHEL\/Fedora (latest version i.e. systemd based) Linux server reload sshd ##<\/span>\n<span class=\"kw2\">sudo<\/span> systemctl reload sshd \n\u00a0\n<span class=\"co0\">## Debian\/Ubuntu Linux (older version) server reload sshd ##<\/span>\n<span class=\"kw2\">sudo<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>init.d<span class=\"sy0\">\/<\/span><span class=\"kw2\">ssh<\/span> reload\n\u00a0\n<span class=\"co0\">## Debian\/Ubuntu Linux (systemd based latest) server reload sshd ##<\/span>\n<span class=\"kw2\">sudo<\/span> systemctl reload <span class=\"kw2\">ssh<\/span> \n\u00a0\n<span class=\"co0\">## Generic Unix method to reload sshd ##<\/span>\n<span class=\"kw2\">sudo<\/span> <span class=\"kw3\">kill<\/span> <span class=\"re5\">-HUP<\/span> <span class=\"sy0\">`<\/span><span class=\"kw2\">cat<\/span> <span class=\"sy0\">\/<\/span>var<span class=\"sy0\">\/<\/span>run<span class=\"sy0\">\/<\/span>sshd.pid<span class=\"sy0\">`<\/span>\nOR\n<span class=\"kw2\">sudo<\/span> <span class=\"kw3\">kill<\/span> <span class=\"re5\">-HUP<\/span> $<span class=\"br0\">(<\/span><span class=\"kw2\">cat<\/span> <span class=\"sy0\">\/<\/span>var<span class=\"sy0\">\/<\/span>run<span class=\"sy0\">\/<\/span>sshd.pid<span class=\"br0\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h2>5: How to add or replace a passphrase for an existing private key?<\/h2>\n<p>To<span>\u00a0<\/span><a href=\"https:\/\/www.cyberciti.biz\/faq\/howto-ssh-changing-passphrase\/\">to change your passphrase type the following command<\/a>:<br \/><code>ssh-keygen -p<\/code><\/p>\n<h2>6: How do I backup an existing private\/public key?<\/h2>\n<p>Just copy files to your backup server or external USB pen\/hard drive:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"bash\">\n<pre class=\"de1\"><span class=\"co0\">## Copy files to  home based nas server ##<\/span>\nrsync <span class=\"re5\">-avr<\/span> <span class=\"re1\">$HOME<\/span><span class=\"sy0\">\/<\/span>.ssh user<span class=\"sy0\">@<\/span>home.nas-server:<span class=\"sy0\">\/<\/span>path<span class=\"sy0\">\/<\/span>to<span class=\"sy0\">\/<\/span>encrpted<span class=\"sy0\">\/<\/span>nas<span class=\"sy0\">\/<\/span>partition<span class=\"sy0\">\/<\/span>\n\u00a0\n<span class=\"co0\">## Copy files to  usb pen drive mounted at \/mnt\/usb ##<\/span>\n<span class=\"kw2\">cp<\/span> <span class=\"re5\">-avr<\/span> <span class=\"re1\">$HOME<\/span><span class=\"sy0\">\/<\/span>.ssh<span class=\"sy0\">\/<\/span> <span class=\"sy0\">\/<\/span>mnt<span class=\"sy0\">\/<\/span>usb<span class=\"sy0\">\/<\/span>backups<span class=\"sy0\">\/<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<h2>How do I protect my ssh keys?<\/h2>\n<ol>\n<li>Always use a strong passphrase.<\/li>\n<li>Do not share your private keys anywhere online or store in insecure cloud storage.<\/li>\n<li>Restrict privileges of the account.<\/li>\n<\/ol>\n<h2>How do I create and setup an OpenSSH config file to create shortcuts for servers I frequently access?<\/h2>\n<p>See<span>\u00a0<\/span><a href=\"https:\/\/www.cyberciti.biz\/faq\/create-ssh-config-file-on-linux-unix\/\">how to create and use an OpenSSH ssh_config file for more<\/a><span>\u00a0<\/span>info.<\/p>\n<h3>Conclusion<\/h3>\n<p>This page explained how to set up ssh keys for authentication purposes. For more info see the following resources:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.cyberciti.biz\/faq\/ssh-passwordless-login-with-keychain-for-scripts\/\">keychain: Set Up Secure Passwordless SSH Access For Backup Scripts<\/a><\/li>\n<li><a href=\"https:\/\/www.cyberciti.biz\/faq\/ubuntu-debian-linux-server-install-keychain-apt-get-command\/\">Ubuntu \/ Debian Linux Server Install Keychain SSH Key Manager For OpenSSH<\/a><\/li>\n<li>Man pages \u2013 ssh-keygen(1)<\/li>\n<li>OpenSSH project<span>\u00a0<\/span><a href=\"https:\/\/www.openssh.com\/\" rel=\"noopener noreferrer\" target=\"_blank\">homepage here<\/a>.<\/li>\n<\/ul>\n<p>And, there you have it, ssh set up with public key based authentication for Linux or Unix-like systems.<\/p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]\n","protected":false},"excerpt":{"rendered":"<p>This page explains a public key and shows you how to set up SSH keys on a Linux or Unix-like server. I am assuming that you are using Linux or Unix-like server and client with the following software:\u00a0 OpenSSH SSHD server OpenSSH ssh client and friends on Linux (Ubuntu, Debian, {Free,Open,Net}BSD, RHEL, CentOS, MacOS\/OSX, AIX, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[3],"tags":[],"class_list":["post-635","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"http:\/\/mastercom.es\/es\/wp-json\/wp\/v2\/posts\/635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mastercom.es\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mastercom.es\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mastercom.es\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mastercom.es\/es\/wp-json\/wp\/v2\/comments?post=635"}],"version-history":[{"count":0,"href":"http:\/\/mastercom.es\/es\/wp-json\/wp\/v2\/posts\/635\/revisions"}],"wp:attachment":[{"href":"http:\/\/mastercom.es\/es\/wp-json\/wp\/v2\/media?parent=635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mastercom.es\/es\/wp-json\/wp\/v2\/categories?post=635"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mastercom.es\/es\/wp-json\/wp\/v2\/tags?post=635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}