{"id":5516,"date":"2026-11-22T14:29:40","date_gmt":"2026-11-22T14:29:40","guid":{"rendered":"https:\/\/geekmungus.co.uk\/?p=5516"},"modified":"2026-11-22T14:29:40","modified_gmt":"2026-11-22T14:29:40","slug":"ssh-agent-on-login-ubuntu-linux","status":"publish","type":"post","link":"https:\/\/geekmungus.co.uk\/?p=5516","title":{"rendered":"SSH Agent on Login (Ubuntu Linux)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The SSH Agent on Linux holds your SSH keys (and certificates) in memory ready to be used by SSH when connecting to a server. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Assuming you already have a key pair, loading the SSH Agent and adding a key is as simple as doing the following. Note I&#8217;m assuming for this example your Private Key is in the file: ~\/.ssh\/id_ed25519, if you have a passphrase on this (which you should), you&#8217;ll be prompted to enter it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$(ssh-agent -s)\nssh-add ~\/.ssh\/id_ed25519<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now the key is loaded, you should be able to see it with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh-add -l<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And your key should then be listed, for example:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"645\" height=\"44\" src=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/11\/image-3.png\" alt=\"\" class=\"wp-image-5527\" srcset=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/11\/image-3.png 645w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/11\/image-3-300x20.png 300w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now assuming you have your public key on a remote server, you can just SSH to it as follows, in my example I&#8217;m logging on as the ansible user on the remote machine that has my Public Key deployed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh ansible@192.168.102.201<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"458\" height=\"79\" src=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/11\/image-4.png\" alt=\"\" class=\"wp-image-5528\" srcset=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/11\/image-4.png 458w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/11\/image-4-300x52.png 300w\" sizes=\"auto, (max-width: 458px) 100vw, 458px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Of course, if you wanted to login and specify the key file directly, i.e. not using the SSH Agent, you can with the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh -i ~\/.ssh\/id_ed25519 ansible@192.168.102.201<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Make it Automatic<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">So, to make this a bit more straight forward, we can make the SSH Agent load at the point when you login to your management machine. We first edit your BASH profile.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi ~\/.profile<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then add the following to the bottom of the file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Load SSH Agent\nif &#91; -z \"$SSH_AUTH_SOCK\" ] ; then\n    eval $(ssh-agent -s)\n    ssh-add\nfi<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll notice the ssh-add line, this just loads all or any keys into the SSH agent that are in the default .ssh key location, i.e. <strong>~\/.ssh\/<\/strong>, if you want to specify a specific key, then you need to change the ssh-add line to include the path to the private key of your choice.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If however you just want it to start the SSH Agent automatically, just leave this line out.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Passphrases<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A note about passphrases. You should have a passphrase added to your SSH Keys as a matter of course, because of this you&#8217;d need to enter the passphrase on each logon so the SSH Agent can access and load the key. This can become tiresome, so its recommended to just load in the key you need when you need it, just use the SSH Agent automatically being loaded instead.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The SSH Agent on Linux holds your SSH keys (and certificates) in memory ready to be used by SSH when connecting to a server. Assuming you already have a key pair, loading the SSH Agent and adding a key is as simple as doing the following. Note I&#8217;m assuming for this example your Private Key &#8230; <a title=\"SSH Agent on Login (Ubuntu Linux)\" class=\"read-more\" href=\"https:\/\/geekmungus.co.uk\/?p=5516\" aria-label=\"Read more about SSH Agent on Login (Ubuntu Linux)\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":4373,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,20,22],"tags":[],"class_list":["post-5516","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-random","category-security"],"_links":{"self":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/5516","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5516"}],"version-history":[{"count":2,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/5516\/revisions"}],"predecessor-version":[{"id":5529,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/5516\/revisions\/5529"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/media\/4373"}],"wp:attachment":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}