{"id":2473,"date":"2023-10-29T16:02:55","date_gmt":"2023-10-29T15:02:55","guid":{"rendered":"https:\/\/labalec.fr\/erwan\/?p=2473"},"modified":"2025-01-04T14:59:06","modified_gmt":"2025-01-04T13:59:06","slug":"ssh-or-sftp-with-a-private-key","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=2473","title":{"rendered":"SSH or SFTP with a private key"},"content":{"rendered":"\n<p>Get your binaries from <a href=\"https:\/\/github.com\/erwan2212\/ssh-fpc\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p>1.On your source host, generate a ssh key pair (private and public) : <strong>ssh-keygen<\/strong><\/p>\n\n\n\n<p>2.Copy your public key on your target host<\/p>\n\n\n\n<p>3.Add your public key to authorized keys on your target host : <strong>cat id_rsa.pub >> .ssh\/authorized_keys<\/strong><\/p>\n\n\n\n<p>And you should be done (sftp and ssh examples below).<\/p>\n\n\n\n<p>SFTP from your source to target host using your private key : <strong>sftp &#8211;ip=192.168.1.126 &#8211;username=jeedom &#8211;privatekey=%homepath%\\.ssh\\id_rsa &#8211;local_filename=readme.md &#8211;command=put &#8211;debug=true<\/strong><\/p>\n\n\n\n<p>SSH from your source to target host using your private key : <strong>ssh &#8211;ip=192.168.1.126 &#8211;username=jeedom &#8211;privatekey=%homepath%\\.ssh\\id_rsa &#8211;debug=true<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Note1 : libssh2 will accept private keys in both format (RSA PRIVATE KEY or OPENSSH PRIVATE KEY)<\/p>\n\n\n\n<p>Note2 : libssh2 will accept public keys in OpenSSH format only (but will manage to derive the public key from the private key if you dont provide the public key)<\/p>\n\n\n\n<p>Note3 : on linux, you can convert a public key generated by OpenSSL (in PEM format) to OpenSSH<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh-keygen -i -m PKCS8 -f public.pem &gt; public.pub<\/code><\/pre>\n\n\n\n<p>Note4:<\/p>\n\n\n\n<p>You can push your public key like below:<\/p>\n\n\n\n<p><strong>ssh &#8211;ip=192.168.1.126 &#8211;username=jeedom &#8211;password=Mjeedom96 &#8211;put &#8211;filename=id_rsa.pub<\/strong><\/p>\n\n\n\n<p><strong>ssh &#8211;ip=192.168.1.126 &#8211;username=jeedom &#8211;password=Mjeedom96 &#8211;delay=250 &#8211;command=\u00a0\u00bbcat id_rsa.pub &gt;&gt; .ssh\/authorized_keys\u00a0\u00bb<\/strong><\/p>\n\n\n\n<p>or (pipe in)<\/p>\n\n\n\n<p><strong>echo \u00ab\u00a0cat id_rsa.pub &gt;&gt; .ssh\/authorized_keys\u00a0\u00bb | ssh &#8211;ip=192.168.1.126 &#8211;username=jeedom &#8211;password=Mjeedom96<\/strong><\/p>\n\n\n\n<p>Note5: don&rsquo;t forget to chmod 700 * in .ssh folder (and check cat \/var\/log\/auth.log in case you get access denied)<\/p>\n\n\n\n<p>Note6 : if still not working, check your \/etc\/ssh\/sshd_config for the below enabled parameters<\/p>\n\n\n\n<p>PubkeyAuthentication yes<br>RSAAuthentication yes<br>HostKeyAlgorithms +ssh-rsa<br>PubkeyAcceptedKeyTypes +ssh-rsa<br>HostbasedAcceptedKeyTypes +ssh-rsa<br>AuthorizedKeysFile .ssh\/authorized_keys<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Get your binaries from here. 1.On your source host, generate a ssh key pair (private and public) : ssh-keygen 2.Copy your public key on your target host 3.Add your public key to authorized keys on your target host : cat id_rsa.pub >> .ssh\/authorized_keys And you should be done (sftp and ssh examples below). SFTP from <a href='https:\/\/labalec.fr\/erwan\/?p=2473' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[141,142],"class_list":["post-2473","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-sftp","tag-ssh","category-1-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/2473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2473"}],"version-history":[{"count":15,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/2473\/revisions"}],"predecessor-version":[{"id":2548,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/2473\/revisions\/2548"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}