VOOZH about

URL: https://thenewstack.io/ssh-made-easy-with-ssh-agent-and-ssh-config/

⇱ SSH Made Easy with SSH Agent and SSH Config - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2021-08-27 03:00:08
SSH Made Easy with SSH Agent and SSH Config
tutorial,
Security

SSH Made Easy with SSH Agent and SSH Config

Streamline SSH with two very specific SSH tools: ssh-agent and the SSH config files.
Aug 27th, 2021 3:00am by Jack Wallen
👁 Featued image for: SSH Made Easy with SSH Agent and SSH Config
Feature Photo by Kristina Flour on Unsplash.

Chances are pretty good you use Secure Shell to log into remote servers.  SSH is well-known for being a (mostly) secure protocol that not only makes remote administration/development simple, it’s also one of your best tools for interacting with your cloud-hosted virtual machines. In fact, without SSH, working remotely on Linux machines, be they hosted in the cloud or an on-premise data center, would be a major challenge, if not entirely impossible.

So good thing SSH is highly configurable and easy to work with. Right?

You might be wondering how any tool that’s primarily used from the command line could be easy to work with. Fortunately, SSH includes several features and add-ons to help simplify and secure its usage.

Today, I want to introduce you to are two very specific SSH tools: ssh-agent and the SSH config files.

What is SSH Agent?

The ssh-agent tool, in conjunction with SSH key authentication, makes it possible for you to start a session and, as long as you are within that session, you can log in and out of a remote server without having to type an SSH password or authentication passphrase. Once you’ve finished with your remote work, end the session and all is well.

But how do you work with this feature? Let me show you.

Before we do, we need to set up SSH key authentication. To do this, head over to the machine you’ll be using to log into the remote server and open a terminal window. From there, create a new SSH key with the command:

ssh-keygen

Once you’ve created your SSH key, you’ll then need to copy it to the server you’ll be logging into. Do that with the command:

ssh-copy-id SERVER

Where SERVER is the IP address or domain of the remote server.

Now, when you attempt to SSH into the remote server, it will ask you for your SSH keyphrase instead of your user password.

First step taken care of.

Now, how do we make use of ssh-agent? Easy. From the terminal, issue the command:

eval `ssh-agent`

You will be returned an Agent PID and then back to your terminal. You might think, “Nothing has changed!” But it has. You’re now in an SSH Agent session.

Next, add your SSH key with the command:

ssh-add

You will be prompted for your SSH key passphrase.

Attempt to SSH to the remote server again. This time, you won’t be prompted for your password or passphrase, you’ll simply be allowed in. Exit out of that remote session and attempt to log in again. Same results. This behavior will continue until you close the SSH Agent session with the exit command.

The Big Caveat

You’ve probably already figured out the caveat to using SSH Agent. You might have exited out of that SSH session, but failed to exit from the SSH Agent session. Should that be the case, anyone with the password to your desktop and the IP address/domain of your remote server can start a new remote session. Because of this, it’s imperative that you either always lock your desktop environment or remember to exit the SSH Agent session when you’re done. Fail to do either one of those things, and you leave yourself open for trouble.

SSH Config

Now that we’ve helped to make your SSH remote sessions a bit more secure by way of SSH key authentication and SSH Agent, we can now make it a bit more convenient. SSH includes a very handy feature in the SSH config file. This file is located in your ~/.ssh directory and is simply called config.

With the SSH config file, you can create individual configurations for your various SSH connections. This is a means of really simplifying all your SSH connections. For example: Let’s say you have several servers you frequently remote into and each connection uses a different username. Let’s call those servers:

  • AWS
  • GoogleCloud
  • Azure
  • Web
  • DB

And with each of those connections you log in with a different user name, so:

  • AWS – olivia
  • GoogleCloud – bethany
  • Azure – trinity
  • Web – janet
  • DB – chenica

What if, instead of having to type out the entire SSH command  — as in ssh olivia@SERVER – where SERVER is the IP address of your AWS-hosted virtual server — you could simply type:

ssh AWS

You can do just that. Let me show you how. I’ll demonstrate on macOS, but the process is the same if you’re using Linux as the client.

Create a new configuration file by opening the terminal application and issuing the command:

nano ~/.ssh/config

Each config entry will look something like this:

Host AWS
   HostName ADDRESS
   User olivia
   IdentityFile ~/.ssh/id_rsa.pub

The above configuration breaks down like this:

  • Host — the nickname you’ll use for the host.
  • HostName — the IP address or domain of the remote server.
  • User — the username associated with the remote account.
  • IdentityFile — the location of your SSH key authentication file for the account.

Obviously, if you’re using SSH key authentication for each account and the usernames are different, you’ll have to create SSH authentication keys for each user and have read access to those files from the user account that will be launching the SSH sessions.

Create entries for each of those remote servers. So the file could look something like this:

Host AWS
   HostName ADDRESS
   User olivia
   IdentityFile ~/.ssh/id_rsa_olivia.pub

Host GoogleCloud
   HostName ADDRESS
   User bethany
   IdentityFile ~/.ssh/id_rsa_bethany.pub

Host AZURE
   HostName ADDRESS
   User trinity
   IdentityFile ~/.ssh/id_rsa_trinity.pub

Host WEB
   HostName ADDRESS
   User janet
   IdentityFile ~/.ssh/id_rsa_janet.pub

Host DB
   HostName ADDRESS
   User chenica
   IdentityFile ~/.ssh/id_rsa_chenica.pub

Where ADDRESS is the IP address or domain of your remote server.

Save and close that file.

The next time you need to log into one of those connections, all you’d do is use any one of the following commands:

ssh AWS

ssh GoogleCloud

ssh AZURE

ssh WEB

ssh DB

That’s it. And if you use this in conjunction with ssh-agent, you’re life has become even easier.

Conclusion

Having to constantly SSH into and out of machines, the repetition can get tedious. And if you have a large number of servers you remote into, you might not even remember the remote IP/ domain addresses or the usernames associated with those remote accounts. Using ssh-agent and the SSH config file can go a long way to making your work a bit more efficient.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.