It sounds like what you're after is a way to store all of your ssh
config and variables for your project in the project directory, and also, for paths to be processed relative to an included ssh config file, rather than the current path.
The short answer is no - AFAIK, ssh_config
includes behave similarly to a C
#include
- you can treat them as expanding the referenced file into the current file.
That being said, you have have a few options to accomplish this in an extensible manner, with a degree of convention - I personally do version a lot of my ssh
configs, My best suggestion is this:
Under your project root, store your ssh
configs under one directory
my_project/
├── _config.yml
├── _ssh_config
│ └── server-1
│ ├── id_rsa
│ └── server-1.config
└── src
3 directories, 3 files
Write server-1.config
like this:
Host projectname-server-1
User root
Hostname server-1.example.com
# Our identity file is found in folder under ~/.ssh
IdentityFile ~/.ssh/config.d/server-1/id_rsa
Under ~/.ssh/
make a new folder, config.d
mkdir -p ~/.ssh/config.d
To reference your project specific ssh files, you can symlink your my_project/_ssh_config/server-1
into config.d
ln -s path/to/my_project/_ssh_config/server-1 ~/.ssh/config.d/server-1
Update your Include
directive in ~/.ssh/config
:
# Relative "Include" paths are assumed to be relative to ~/.ssh/
Include config.d/server-1/server-1.config
Now, your ~/.ssh
looks like this:
.ssh/
├── config
└── config.d
└── server-1 -> /path/to/my_project/_ssh_config/server-1/
├── id_rsa
└── server-1.config
2 directories, 3 files
The upshot of this approach is that you can easily extend it to server-2
, 3, 4 etc, or to other projects. Just symlink path/to/server-x
into config.d
, and you can use globs in your user-level Include
to take care of it:
Include config.d/**/*.config
I'd suggest that storing ssh
keys in the project sounds unconventional, potentially dangerous, and not particularly useful. If your goal is portability for your config, I'd suggest making an exception for the path of your private key.