{"id":872,"date":"2015-08-13T14:25:09","date_gmt":"2015-08-13T21:25:09","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=872"},"modified":"2015-08-13T14:25:09","modified_gmt":"2015-08-13T21:25:09","slug":"force-ssh-client-to-use-given-private-key-identity-file","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2015\/08\/13\/force-ssh-client-to-use-given-private-key-identity-file\/","title":{"rendered":"Force SSH Client To Use Given Private Key ( identity file )"},"content":{"rendered":"<p><span style=\"text-decoration: underline;\"><\/span><\/p>\n<p><span class=\"drop_cap\">R<\/span>ecently, my desktop hard disk crashed. So I reinstalled Linux and created a new set of private RSA keys for authentication. However, two of my remote UNIX servers still uses old DSA keys. I do not remember root password for those servers. I do have backup of private and public DSA keys and currently stored in \/backup\/home\/user\/.ssh\/id_dsa and \/backup\/home\/user\/.ssh\/id_dsa.pub. How do I force my ssh clients to use identity file \/backup\/home\/user\/.ssh\/id_dsa to get back to my remote UNIX servers?<br \/>\n<span id=\"more-7442\"><\/span><\/p>\n<div><a title=\"See all UNIX related articles\/faq\" href=\"http:\/\/www.cyberciti.biz\/faq\/category\/unix\/\"><img decoding=\"async\" src=\"http:\/\/c.cyberciti.biz\/cbzcache\/3rdparty\/unix-logo.gif\" alt=\"\" border=\"0\" \/><\/a><\/div>\n<p>The ssh client allows you to selects a file from which the identity (private key) for RSA or DSA authentication is read. The default is ~\/.ssh\/identity for protocol version 1, and ~\/.ssh\/id_rsa and ~\/.ssh\/id_dsa for protocol version 2. Identity files may also be specified on a per-host basis in the configuration file. It is possible to have multiple -i options (and multiple identities specified in configuration files). The syntax is as follows:<\/p>\n<pre class=\"bash\">ssh -i \/path\/to\/id_rsa user@server.nixcraft.com\nssh -i \/path\/to\/id_dsa user@server2.nixcraft.net.i<\/pre>\n<p>To use \/backup\/home\/user\/.ssh\/id_dsa, enter:<\/p>\n<pre class=\"bash\">ssh -i \/backup\/home\/user\/.ssh\/id_dsa user@unixserver1.nixcraft.com<\/pre>\n<h2>~\/.ssh\/config SSH Client Configuration<\/h2>\n<p>You can set identity file in ~\/.ssh\/config as follows:<br \/>\n<code>vi ~\/.ssh\/config<\/code><br \/>\nAdd both host names and their identity file as follows:<\/p>\n<pre>Host server1.nixcraft.com\n  IdentityFile ~\/backups\/.ssh\/id_dsa\nHost server2.nixcraft.com\n  IdentityFile \/backup\/home\/userName\/.ssh\/id_rsa<\/pre>\n<p>You can add other settings per host such as port number, X11 forwarding, real hostnames and much more. Save and close the file. You can connect as follows:<\/p>\n<pre class=\"bash\">ssh user@server2.nixcraft.com\nssh root@server1.nixcraft.com<\/pre>\n<h4>Recommended readings:<\/h4>\n<ul>\n<li>See the ssh_config and sshd man page for more information.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Recently, my desktop hard disk crashed. So I reinstalled Linux and created a new set of private RSA keys for authentication. However, two of my&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-872","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=872"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/872\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}