{"id":3254,"date":"2007-02-01T22:16:19","date_gmt":"2007-02-01T13:16:19","guid":{"rendered":"https:\/\/www.pistolfly.com\/weblog\/?p=3254"},"modified":"2017-10-18T17:16:20","modified_gmt":"2017-10-18T08:16:20","slug":"set-up-public-key-authentication-with-ssh","status":"publish","type":"post","link":"https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html","title":{"rendered":"Set up public key authentication with SSH"},"content":{"rendered":"<h3>1. Generate a keypair using the ssh-keygen<\/h3>\n<pre class=\"command-line\">$ ssh-keygen -t rsa<\/pre>\n<p>You will be prompted to supply a filename for saving the keypair. Press enter to accept the default filename.<br \/>\nThen enter passphrase twice.<br \/>\nThe keypair files below are generated in ~\/.ssh.<\/p>\n<ul>\n<li>id_rsa<\/li>\n<li>id_rsa.pub<\/li>\n<\/ul>\n<h3>2. Add public key to the remote SSH server<\/h3>\n<p>Copy the public key file generated in step 1 to the user's home directory of remote server using scp or ftp.<\/p>\n<pre class=\"command-line\">$ scp ~\/.ssh\/id_rsa.pub user@host:\r\n<\/pre>\n<p>On remote server register the public key to ~\/.ssh\/authorized_keys using cat command and redirection.<\/p>\n<pre class=\"command-line\">$ cat id_rsa.pub &gt;&gt; ~\/.ssh\/authorized_keys\r\n<\/pre>\n<p>Modify the permissions of ~\/.ssh directory and ~\/.ssh\/authorized_keys to allow only owner of them to read or write.<\/p>\n<pre class=\"command-line\">$ chmod 700 ~\/.ssh\r\n$ chmod 600 ~\/.ssh\/authorized_keys\r\n<\/pre>\n<ul>\n<li>Pay attention to the permission of the user's home directory of client side.<br \/>\nIn case that write permission for other than owner is set, it's bad.<br \/>\nFor example, when file mode of \/home\/hoge is 777 and you attempt to connect with SSH, you will have an error below.<\/p>\n<pre class=\"command-line\">Permission denied (publickey,gssapi-with-mic).\r\n<\/pre>\n<p>In this case the log file of server side (\/var\/log\/secure) says<\/p>\n<pre class=\"command-line\">Authentication refused: bad ownership or modes for directory \/home\/hoge\r\n<\/pre>\n<p>You should set home directory's permissions to 700, 711, or 755.<\/li>\n<\/ul>\n<h3>3. Attempt to log in with public key authentication<\/h3>\n<pre class=\"command-line\">$ ssh -l user host\r\n<\/pre>\n<p>You will be prompted to enter passphrase then enter the passphrase which you specified in executing ssh-keygen command.<br \/>\n\uff08<strong>Notice the passphrase is NOT a password of the user<\/strong>\uff09<\/p>\n<h3>4. Client side<\/h3>\n<p>Copy private key file (id_rsa) to the client side ~\/.ssh<\/p>\n<ul>\n<li>Pay attention to the permission of the private key file.<br \/>\nBelow is an error on Mac OS X.<\/p>\n<pre class=\"command-line\">@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\n@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @\r\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\nPermissions 0640 for '\/Users\/xxx\/.ssh\/id_rsa' are too open.\r\nIt is recommended that your private key files are NOT accessible by others.\r\nThis private key will be ignored.\r\nbad permissions: ignore key: \/Users\/xxx\/.ssh\/id_rsa\r\nPermission denied (publickey,gssapi-with-mic).\r\n<\/pre>\n<p>Set the permissions of id_rsa to 600 and it will be OK.<\/li>\n<li>If you use cwRsync, copy private key file (id_rsa) in .ssh directory under the HOME environment variable. (Same as directory in which known_hosts is created)\n<p>For example:<\/p>\n<p>If HOME is \/home\/pistolfly and cygwin directory is C:\\cygwin, use C:\\cygwin\\home\\.ssh.<br \/>\n\uff08You can also specify path to private key file with -i option in rsync -e or --rsh options\uff09<\/li>\n<\/ul>\n<h3>5. Disable password authentication<\/h3>\n<p>Edit \/etc\/ssh\/sshd_config (server side)<\/p>\n<p>Modify<\/p>\n<pre class=\"prettyprint\">PasswordAuthentication yes\r\n<\/pre>\n<p>to<\/p>\n<pre class=\"prettyprint\">PasswordAuthentication no\r\n<\/pre>\n<p>Disable root login.<\/p>\n<pre class=\"prettyprint\">PermitRootLogin no\r\n<\/pre>\n<p>Reload sshd as a root. <strong>Don't logout as root yet.<\/strong><\/p>\n<pre class=\"command-line\">$ \/etc\/init.d\/sshd reload\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. Generate a keypair using the ssh-keygen $ ssh-keygen -t rsa You will be prompted to supply a filename for s &hellip; <a href=\"https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Set up public key authentication with SSH<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"116","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,19],"tags":[],"class_list":["post-3254","post","type-post","status-publish","format-standard","hentry","category-linux","category-security","en-US"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Set up public key authentication with SSH - Pistolfly<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Set up public key authentication with SSH - Pistolfly\" \/>\n<meta property=\"og:description\" content=\"1. Generate a keypair using the ssh-keygen $ ssh-keygen -t rsa You will be prompted to supply a filename for s &hellip; Continue reading Set up public key authentication with SSH &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html\" \/>\n<meta property=\"og:site_name\" content=\"Pistolfly\" \/>\n<meta property=\"article:published_time\" content=\"2007-02-01T13:16:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-10-18T08:16:20+00:00\" \/>\n<meta name=\"author\" content=\"Pistolfly\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pistolfly\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/en\\\/2007\\\/02\\\/set-up-public-key-authentication-with-ssh.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/en\\\/2007\\\/02\\\/set-up-public-key-authentication-with-ssh.html\"},\"author\":{\"name\":\"Pistolfly\",\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/#\\\/schema\\\/person\\\/e779e918730b507907b3a35b77a9a2ab\"},\"headline\":\"Set up public key authentication with SSH\",\"datePublished\":\"2007-02-01T13:16:19+00:00\",\"dateModified\":\"2017-10-18T08:16:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/en\\\/2007\\\/02\\\/set-up-public-key-authentication-with-ssh.html\"},\"wordCount\":354,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/#\\\/schema\\\/person\\\/e779e918730b507907b3a35b77a9a2ab\"},\"articleSection\":[\"Linux\",\"security\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/en\\\/2007\\\/02\\\/set-up-public-key-authentication-with-ssh.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/en\\\/2007\\\/02\\\/set-up-public-key-authentication-with-ssh.html\",\"url\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/en\\\/2007\\\/02\\\/set-up-public-key-authentication-with-ssh.html\",\"name\":\"Set up public key authentication with SSH - Pistolfly\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/#website\"},\"datePublished\":\"2007-02-01T13:16:19+00:00\",\"dateModified\":\"2017-10-18T08:16:20+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/en\\\/2007\\\/02\\\/set-up-public-key-authentication-with-ssh.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/en\\\/2007\\\/02\\\/set-up-public-key-authentication-with-ssh.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/en\\\/2007\\\/02\\\/set-up-public-key-authentication-with-ssh.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u30db\u30fc\u30e0\",\"item\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Set up public key authentication with SSH\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/#website\",\"url\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/\",\"name\":\"Pistolfly\",\"description\":\"Developer Blog\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/#\\\/schema\\\/person\\\/e779e918730b507907b3a35b77a9a2ab\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/#\\\/schema\\\/person\\\/e779e918730b507907b3a35b77a9a2ab\",\"name\":\"Pistolfly\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g\",\"caption\":\"Pistolfly\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g\"},\"description\":\"Software Engineer in Tokyo, Japan\",\"url\":\"https:\\\/\\\/www.pistolfly.com\\\/weblog\\\/author\\\/pistolfly\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Set up public key authentication with SSH - Pistolfly","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:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html","og_locale":"en_US","og_type":"article","og_title":"Set up public key authentication with SSH - Pistolfly","og_description":"1. Generate a keypair using the ssh-keygen $ ssh-keygen -t rsa You will be prompted to supply a filename for s &hellip; Continue reading Set up public key authentication with SSH &rarr;","og_url":"https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html","og_site_name":"Pistolfly","article_published_time":"2007-02-01T13:16:19+00:00","article_modified_time":"2017-10-18T08:16:20+00:00","author":"Pistolfly","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Pistolfly","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html#article","isPartOf":{"@id":"https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html"},"author":{"name":"Pistolfly","@id":"https:\/\/www.pistolfly.com\/weblog\/#\/schema\/person\/e779e918730b507907b3a35b77a9a2ab"},"headline":"Set up public key authentication with SSH","datePublished":"2007-02-01T13:16:19+00:00","dateModified":"2017-10-18T08:16:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html"},"wordCount":354,"commentCount":0,"publisher":{"@id":"https:\/\/www.pistolfly.com\/weblog\/#\/schema\/person\/e779e918730b507907b3a35b77a9a2ab"},"articleSection":["Linux","security"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html","url":"https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html","name":"Set up public key authentication with SSH - Pistolfly","isPartOf":{"@id":"https:\/\/www.pistolfly.com\/weblog\/#website"},"datePublished":"2007-02-01T13:16:19+00:00","dateModified":"2017-10-18T08:16:20+00:00","breadcrumb":{"@id":"https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pistolfly.com\/weblog\/en\/2007\/02\/set-up-public-key-authentication-with-ssh.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u30db\u30fc\u30e0","item":"https:\/\/www.pistolfly.com\/weblog"},{"@type":"ListItem","position":2,"name":"Set up public key authentication with SSH"}]},{"@type":"WebSite","@id":"https:\/\/www.pistolfly.com\/weblog\/#website","url":"https:\/\/www.pistolfly.com\/weblog\/","name":"Pistolfly","description":"Developer Blog","publisher":{"@id":"https:\/\/www.pistolfly.com\/weblog\/#\/schema\/person\/e779e918730b507907b3a35b77a9a2ab"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pistolfly.com\/weblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.pistolfly.com\/weblog\/#\/schema\/person\/e779e918730b507907b3a35b77a9a2ab","name":"Pistolfly","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g","caption":"Pistolfly"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/0b3ddb2859adabf28a2b97ae9fff98772ddffc46088d11cad2b9a2cef66115e7?s=96&d=mm&r=g"},"description":"Software Engineer in Tokyo, Japan","url":"https:\/\/www.pistolfly.com\/weblog\/author\/pistolfly"}]}},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paorzz-Qu","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/posts\/3254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/comments?post=3254"}],"version-history":[{"count":14,"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/posts\/3254\/revisions"}],"predecessor-version":[{"id":4131,"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/posts\/3254\/revisions\/4131"}],"wp:attachment":[{"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/media?parent=3254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/categories?post=3254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pistolfly.com\/weblog\/wp-json\/wp\/v2\/tags?post=3254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}