[{"data":1,"prerenderedAt":498},["ShallowReactive",2],{"i-lucide:sun-moon":3,"i-lucide:menu":8,"post-\u002Fblog\u002F2024-05-10-using-ssh-agent":10,"surround-\u002Fblog\u002F2024-05-10-using-ssh-agent":481,"i-lucide:arrow-left":492,"i-lucide:sparkles":494,"i-lucide:user":496},{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":7},0,24,false,"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M12 2v2m2.837 12.385a6 6 0 1 1-7.223-7.222c.624-.147.97.66.715 1.248a4 4 0 0 0 5.26 5.259c.589-.255 1.396.09 1.248.715M16 12a4 4 0 0 0-4-4m7-3l-1.256 1.256M20 12h2\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":9},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M4 5h16M4 12h16M4 19h16\"\u002F>",{"id":11,"title":12,"authors":13,"body":16,"date":466,"description":467,"extension":468,"meta":469,"navigation":304,"path":472,"seo":473,"stem":474,"tags":475,"toc":6,"__hash__":480},"blog\u002Fblog\u002F2024-05-10-using-ssh-agent.md","Setting Up ed25519 SSH Keys and ssh-agent in WSL and Linux",[14,15],"gpt","pfarmer",{"type":17,"value":18,"toc":454},"minimark",[19,28,33,36,52,56,61,64,91,95,98,123,127,134,138,142,148,163,167,173,189,264,275,444,450],[20,21,22,23,27],"p",{},"Secure Shell (SSH) is a fundamental tool for developers, system administrators, and anyone requiring secure remote access to servers and systems. SSH keys provide a more secure method of authentication than traditional passwords by using a private-public key pair. This blog post guides you through setting up ed25519 SSH keys and configuring ",[24,25,26],"code",{},"ssh-agent"," in both Windows Subsystem for Linux (WSL) and native Linux environments to enhance the security and simplicity of your remote connections.",[29,30,32],"h2",{"id":31},"understanding-ssh-keys-and-ssh-agent","Understanding SSH Keys and ssh-agent",[20,34,35],{},"Let’s begin by understanding the core components:",[37,38,39,47],"ul",{},[40,41,42,46],"li",{},[43,44,45],"strong",{},"SSH Keys",": An SSH key pair consists of a private key, which is kept secret, and a public key, which is shared with servers. Authentication is done by proving you possess the private key without transmitting it over the network.",[40,48,49,51],{},[43,50,26],{},": This background program caches your private keys and handles key-based authentication on your behalf. It's especially useful for managing multiple keys or automating scripts without the need to enter passwords repeatedly.",[29,53,55],{"id":54},"setting-up-ssh-keys","Setting Up SSH Keys",[57,58,60],"h3",{"id":59},"_1-generating-ssh-keys","1. Generating SSH Keys",[20,62,63],{},"To generate ed25519 SSH keys, follow these steps for both WSL and Linux:",[65,66,67,70,81,88],"ol",{},[40,68,69],{},"Open a terminal.",[40,71,72,73,76,77,80],{},"Run the command to create a new SSH key pair:\n",[24,74,75],{},"ssh-keygen -t ed25519 -C \"your_email@example.com\"","\nReplace ",[24,78,79],{},"\"your_email@example.com\""," with your email or a label for this key. This command creates an ed25519 key pair, known for its high security and efficiency.",[40,82,83,84,87],{},"You will be prompted to enter a file path to save the keys. The default is usually ",[24,85,86],{},"~\u002F.ssh\u002Fid_ed25519",". Press Enter to accept the default or specify a different path.",[40,89,90],{},"Enter a passphrase for additional security when prompted. This passphrase will protect your private key on your local machine.",[57,92,94],{"id":93},"_2-copying-the-public-key-to-the-server","2. Copying the Public Key to the Server",[20,96,97],{},"To authenticate using your new SSH key, you need to place the public key on the server:",[65,99,100,106,109],{},[40,101,102,103],{},"Display your public key with:\n",[24,104,105],{},"cat ~\u002F.ssh\u002Fid_ed25519.pub",[40,107,108],{},"Copy the displayed key.",[40,110,111,112,115,116,76,119,122],{},"On the server, paste this key into ",[24,113,114],{},"~\u002F.ssh\u002Fauthorized_keys",". If you can SSH into the server with a password, use this shortcut:\n",[24,117,118],{},"ssh-copy-id -i ~\u002F.ssh\u002Fid_ed25519.pub username@server_address",[24,120,121],{},"username@server_address"," with your actual server login.",[57,124,126],{"id":125},"_3-testing-your-ssh-connection","3. Testing Your SSH Connection",[20,128,129,130,133],{},"Test the SSH connection to ensure your key works:\n",[24,131,132],{},"ssh username@server_address","\nIf set up correctly, you'll be prompted for the passphrase of your private key (if you set one) rather than the user's password on the server.",[29,135,137],{"id":136},"configuring-ssh-agent","Configuring ssh-agent",[57,139,141],{"id":140},"_1-starting-ssh-agent","1. Starting ssh-agent",[20,143,144,145,147],{},"For both WSL and Linux, you start ",[24,146,26],{}," to manage your keys:",[65,149,150,156],{},[40,151,152,153],{},"Start the agent:\n",[24,154,155],{},"eval \"$(ssh-agent -s)\"",[40,157,158,159,162],{},"Add your private key to the agent:\n",[24,160,161],{},"ssh-add ~\u002F.ssh\u002Fid_ed25519","\nIf you used a different path or key name, adjust the path accordingly.",[57,164,166],{"id":165},"_2-automating-ssh-agent-on-startup","2. Automating ssh-agent on Startup",[20,168,169,170,172],{},"To avoid manually starting ",[24,171,26],{}," every session, automate it:",[37,174,175],{},[40,176,177,180,181,184,185,188],{},[43,178,179],{},"In Linux",": Add the following to your ",[24,182,183],{},"~\u002F.bashrc"," or ",[24,186,187],{},"~\u002F.zshrc",":",[190,191,196],"pre",{"className":192,"code":193,"language":194,"meta":195,"style":195},"language-bash shiki shiki-themes github-light github-dark-default","if [ -z \"$SSH_AUTH_SOCK\" ]; then\n    eval \"$(ssh-agent -s)\"\n    ssh-add ~\u002F.ssh\u002Fid_ed25519\nfi\n","bash","",[24,197,198,230,249,258],{"__ignoreMap":195},[199,200,203,207,211,214,218,221,224,227],"span",{"class":201,"line":202},"line",1,[199,204,206],{"class":205},"sDgYj","if",[199,208,210],{"class":209},"szmH1"," [ ",[199,212,213],{"class":205},"-z",[199,215,217],{"class":216},"sNbzA"," \"",[199,219,220],{"class":209},"$SSH_AUTH_SOCK",[199,222,223],{"class":216},"\"",[199,225,226],{"class":209}," ]; ",[199,228,229],{"class":205},"then\n",[199,231,233,237,240,243,246],{"class":201,"line":232},2,[199,234,236],{"class":235},"sPgVT","    eval",[199,238,239],{"class":216}," \"$(",[199,241,26],{"class":242},"sYRkA",[199,244,245],{"class":235}," -s",[199,247,248],{"class":216},")\"\n",[199,250,252,255],{"class":201,"line":251},3,[199,253,254],{"class":242},"    ssh-add",[199,256,257],{"class":216}," ~\u002F.ssh\u002Fid_ed25519\n",[199,259,261],{"class":201,"line":260},4,[199,262,263],{"class":205},"fi\n",[37,265,266],{},[40,267,268,271,272,274],{},[43,269,270],{},"In WSL",": We need to manage ",[24,273,26],{}," differently because of how WSL works. Paste this into your .bashrc file in your home directory.",[190,276,278],{"className":192,"code":277,"language":194,"meta":195,"style":195},"ssh_pid=$(pidof ssh-agent)\n\n# If the agent is not running, start it, and save the environment to a file\nif [ \"$ssh_pid\" = \"\" ]; then\n        ssh_env=\"$(ssh-agent -s)\"\n        echo \"$ssh_env\" | head -n 2 | tee ~\u002F.ssh_agent_env > \u002Fdev\u002Fnull\nfi\n\n# Load the environment from the file\nif [ -f ~\u002F.ssh_agent_env ]; then\n        eval \"$(cat ~\u002F.ssh_agent_env)\"\nfi\n",[24,279,280,300,306,312,335,352,391,396,401,407,425,439],{"__ignoreMap":195},[199,281,282,285,288,291,294,297],{"class":201,"line":202},[199,283,284],{"class":209},"ssh_pid",[199,286,287],{"class":205},"=",[199,289,290],{"class":209},"$(",[199,292,293],{"class":242},"pidof",[199,295,296],{"class":216}," ssh-agent",[199,298,299],{"class":209},")\n",[199,301,302],{"class":201,"line":232},[199,303,305],{"emptyLinePlaceholder":304},true,"\n",[199,307,308],{"class":201,"line":251},[199,309,311],{"class":310},"sPyeA","# If the agent is not running, start it, and save the environment to a file\n",[199,313,314,316,318,320,323,325,328,331,333],{"class":201,"line":260},[199,315,206],{"class":205},[199,317,210],{"class":209},[199,319,223],{"class":216},[199,321,322],{"class":209},"$ssh_pid",[199,324,223],{"class":216},[199,326,327],{"class":205}," =",[199,329,330],{"class":216}," \"\"",[199,332,226],{"class":209},[199,334,229],{"class":205},[199,336,338,341,343,346,348,350],{"class":201,"line":337},5,[199,339,340],{"class":209},"        ssh_env",[199,342,287],{"class":205},[199,344,345],{"class":216},"\"$(",[199,347,26],{"class":242},[199,349,245],{"class":235},[199,351,248],{"class":216},[199,353,355,358,360,363,365,368,371,374,377,379,382,385,388],{"class":201,"line":354},6,[199,356,357],{"class":235},"        echo",[199,359,217],{"class":216},[199,361,362],{"class":209},"$ssh_env",[199,364,223],{"class":216},[199,366,367],{"class":205}," |",[199,369,370],{"class":242}," head",[199,372,373],{"class":235}," -n",[199,375,376],{"class":235}," 2",[199,378,367],{"class":205},[199,380,381],{"class":242}," tee",[199,383,384],{"class":216}," ~\u002F.ssh_agent_env",[199,386,387],{"class":205}," >",[199,389,390],{"class":216}," \u002Fdev\u002Fnull\n",[199,392,394],{"class":201,"line":393},7,[199,395,263],{"class":205},[199,397,399],{"class":201,"line":398},8,[199,400,305],{"emptyLinePlaceholder":304},[199,402,404],{"class":201,"line":403},9,[199,405,406],{"class":310},"# Load the environment from the file\n",[199,408,410,412,414,417,420,423],{"class":201,"line":409},10,[199,411,206],{"class":205},[199,413,210],{"class":209},[199,415,416],{"class":205},"-f",[199,418,419],{"class":205}," ~",[199,421,422],{"class":209},"\u002F.ssh_agent_env ]; ",[199,424,229],{"class":205},[199,426,428,431,433,436],{"class":201,"line":427},11,[199,429,430],{"class":235},"        eval",[199,432,239],{"class":216},[199,434,435],{"class":242},"cat",[199,437,438],{"class":216}," ~\u002F.ssh_agent_env)\"\n",[199,440,442],{"class":201,"line":441},12,[199,443,263],{"class":205},[20,445,446,447,449],{},"By setting up SSH keys and configuring ",[24,448,26],{},", you enhance the security and convenience of your remote connections. This setup eliminates the risk associated with passwords and streamlines your workflow, especially when handling multiple servers or automated tasks. Happy secure connecting!",[451,452,453],"style",{},"html pre.shiki code .sDgYj, html code.shiki .sDgYj{--shiki-default:#D73A49;--shiki-dark:#FF7B72}html pre.shiki code .szmH1, html code.shiki .szmH1{--shiki-default:#24292E;--shiki-dark:#E6EDF3}html pre.shiki code .sNbzA, html code.shiki .sNbzA{--shiki-default:#032F62;--shiki-dark:#A5D6FF}html pre.shiki code .sPgVT, html code.shiki .sPgVT{--shiki-default:#005CC5;--shiki-dark:#79C0FF}html pre.shiki code .sYRkA, html code.shiki .sYRkA{--shiki-default:#6F42C1;--shiki-dark:#FFA657}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sPyeA, html code.shiki .sPyeA{--shiki-default:#6A737D;--shiki-dark:#8B949E}",{"title":195,"searchDepth":251,"depth":251,"links":455},[456,457,462],{"id":31,"depth":232,"text":32},{"id":54,"depth":232,"text":55,"children":458},[459,460,461],{"id":59,"depth":251,"text":60},{"id":93,"depth":251,"text":94},{"id":125,"depth":251,"text":126},{"id":136,"depth":232,"text":137,"children":463},[464,465],{"id":140,"depth":251,"text":141},{"id":165,"depth":251,"text":166},"2024-05-10","Secure Shell (SSH) is a fundamental tool for developers, system administrators, and anyone requiring secure remote access to servers and systems. SSH keys provide a more secure method of authentication than traditional passwords by using a private-public key pair. This blog post guides you through setting up ed25519 SSH keys and configuring ssh-agent in both Windows Subsystem for Linux (WSL) and native Linux environments to enhance the security and simplicity of your remote connections.","md",{"type":470,"layout":471},"post","blog_page","\u002Fblog\u002F2024-05-10-using-ssh-agent",{"title":12,"description":467},"blog\u002F2024-05-10-using-ssh-agent",[476,477,478,479],"devops","mongodb","linux","sysadmin","0RA47xQJ40-z1E80DchqB_jM5yMMJJksFWBu5UfVQ7I",[482,487],{"title":483,"path":484,"stem":485,"date":486,"children":-1},"How to Migrate Data from One MongoDB Database to Another","\u002Fblog\u002F2024-05-08-howto-migrate-a-monogdb","blog\u002F2024-05-08-howto-migrate-a-monogdb","2024-05-08",{"title":488,"path":489,"stem":490,"date":491,"children":-1},"Automating Tasks with systemd timers","\u002Fblog\u002F2024-05-15-using-systemd-timers","blog\u002F2024-05-15-using-systemd-timers","2024-05-15",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":493},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m12 19l-7-7l7-7m7 7H5\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":495},"\u003Cg fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\u003Cpath d=\"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594zM20 2v4m2-2h-4\"\u002F>\u003Ccircle cx=\"4\" cy=\"20\" r=\"2\"\u002F>\u003C\u002Fg>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":497},"\u003Cg fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\u003Cpath d=\"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2\"\u002F>\u003Ccircle cx=\"12\" cy=\"7\" r=\"4\"\u002F>\u003C\u002Fg>",1783616164828]