Skip to content

Instantly share code, notes, and snippets.

@bensig
Created November 6, 2023 20:10
Show Gist options
  • Save bensig/a9b7edb79977dca1f6e40e46f6bdf19a to your computer and use it in GitHub Desktop.
Save bensig/a9b7edb79977dca1f6e40e46f6bdf19a to your computer and use it in GitHub Desktop.
How to setup .ssh env

This is how you can use a config.d directory in your ssh config so that you will have versatility, portability, and customization of your ssh env and commands to connect to servers using simple shortcuts from VS Code and Terminal. Manage multiple identities, keys, servers, everything.

example: ssh prototype or ssh user1@prototype

  1. Make sure you have a .ssh dir with permissions 755 for the dir
  2. Create an SSH key and give it permissions 600
  3. Make an ssh config file by typing nano ~/.ssh/config and put in the line Include config.d/* hit cntrl + x then y when you're done editing
  4. Create a config.d directory mkdir ~/.ssh/config.d
  5. In there, you can add in ssh config files for various projects - for exmaple, personal or work
  6. Let's create one for work cd ~/.ssh/config.d && nano work
  7. You can put your ssh config details into the file for a particular host. The line "Host" defines the name you will use to connect with ssh, Hostname is the address or FQDN to dial, User is the user account, Identity file is the path to your private key - the pub key must be in the server's ~/.ssh/authorized_keys file with the correct permissions
# Server for prototype
Host prototype 34.12.16.12
	Hostname 34.12.16.12
	User ubuntu
	IdentityFile ~/.ssh/id_ed25519
  1. Save the file with cntrl +x then y when you're done adding
  2. Now type ssh prototype and you should connect to the server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment