Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In case it matters:

  • OS: Ubuntu 10.04
  • SSH: OpenSSH_5.3p1 Debian-3ubuntu5

I'd like one SSH config file to include another one. The use case would be to define whatever I want in my default .ssh/config file and then pre-pend a couple of extra things in a separate file (e.g. ~/.ssh/foo.config). I want the second file to incorporate the first one, though, so I don't have to duplicate everything in the first one. Is that doable? Thanks!

share|improve this question
Same question on serverfault:… – guettli Oct 29 '14 at 17:56
up vote 26 down vote accepted

No, to my knowledge this is not possible.

Here are the links to corresponding open feature requests / bug tickets:

share|improve this answer
Also this bug on Debian: – tictacbum Jul 3 '14 at 11:50
OMG. It is hapening. From 2016-04-15 13:01:08 EST: Slightly modified patch applied, this will be in openssh-7.3 – oschrenk Jun 18 at 0:15

If you want to start a ssh client, you could do this in bash:

#files are .ssh/config and ~/.ssh/foo.config
alias ssh='ssh -F <(cat .ssh/config ~/.ssh/foo.config)'

then you use ssh normally and it will have both files read in that order.

For the server daemon sshd you could do the same, just use -f instead of -F and write this down where you start the daemon directly. you don't need an alias.

A second possibility according to the man page is to put the system wide configuration in /etc/ssh/ssh_config and the user one in ~/.ssh/config.

Update Apparently there is some problem with some bash versions and how the devices are created. (see

This is a workaround (though in my opinion ugly):

mkfifo /tmp/ssh_fifo
cat ~/.ssh/config ~/.ssh/foo.config >/tmp/ssh_fifo & 
ssh -F /tmp/ssh_fifo myserver
rm /tmp/ssh_fifo

so if you want, you may create a function out of it (or a script):

ssh() {
    tmp_fifo=$(mktemp -u --suffix=_ssh_fifo)
    mkfifo "$tmp_fifo" 
    cat ~/.ssh/config ~/.ssh/foo.config >"$tmp_fifo" 2>/dev/null & 
    /usr/bin/ssh -F "$tmp_fifo" "$@"
    rm "$tmp_fifo"
share|improve this answer
Thanks for the tip! – Joe Casadonte Apr 23 '12 at 1:07
Sadly this doesn't work on OSX's ssh: Can't open user config file /dev/fd/63: Bad file descriptor – Ash Berlin Aug 23 '12 at 13:10
It does not work for me also on (Ubuntu 11.10) Linux giving the same error as @AshBerlin posted above. – Szymon Jeż Nov 27 '12 at 15:13
@Jeznet I think I found the problem in your case and got an ugly workaround... – estani Nov 27 '12 at 19:31
@AshBerlin you may try it too, this should work also for OSX, until the bug gets fixed – estani Nov 27 '12 at 19:32

Similarly to the other 'ugly' here's mine one-liner:

alias ssh="cat ~/.ssh/config.d/* > ~/.ssh/config; ssh"
share|improve this answer
Note that sftp command will not trigger config recalculation. – Vasya Novikov Mar 13 '15 at 22:44
(I still like the answer because it uses "config.d/" and is very simple.) – Vasya Novikov Mar 13 '15 at 22:49
simple, elegant, yet hacky – code_monk May 29 at 14:31

Well, I kinda cheat to do this. In my bash .profile-ish files I have a block that replaces various pieces of my home directory on login, so I just generate a new one each time. Example:

rm ~/.ssh/config
cat ~/conf/myservers.sshconfig >> ~/.ssh/config

[ -f ~/conf/workservers.sshconfig ] && cat ~/conf/workservers.sshconfig >> ~/.ssh/config
(or something like this:)
for i in `ls ~/conf/sshconfigs` ; do
    cat $i >> ~/.ssh/config

chmod 600 ~/.ssh/config

This also lets me do things like add config blocks to the ssh config file only if i'm on host A or B, but not on my home systems.

Now I know, someone will gripe that if you log in a lot this could cause excessive slowdown, but in practice I've never actually noticed it. And I'm sure you could put this in a script and fire it via cron too.

share|improve this answer

I personally use those commands to compile the ssh config:

alias compile-ssh-config='echo -n > ~/.ssh/config && cat ~/.ssh/*.config > ~/.ssh/config'
alias ssh='compile-ssh-config && ssh'
# (This will get used by other programs depending on the ~/.ssh/config)
# (If you need you can run the compile-ssh-config command via cron etc.)


alias compile-ssh-config='echo -n > ~/.ssh/config-compilation && cat ~/.ssh/*.config > ~/.ssh/config-compilation'
alias ssh='compile-ssh-config && ssh -F ~/.ssh/config-compilation'
# (This is saver and won't over write an existing ~/.ssh/config file)


alias ssh='ssh -F <(cat .ssh/*.config)'

does not work for me, returning:

ssh: Can't open user config file /dev/fd/63: Bad file descriptor

Hope this will be of any help.

share|improve this answer
You could go a step further and combine this with fswatch, for automated compilation on file change – Matt Tagg Feb 28 '15 at 6:34

Another, FUSE-based solution (not tested myself):

"Rather than having to continue managing one big file, [...] instead build a config "file" dynamically from many smaller logical chunks."

I've also found an article doing this via FIFOs:

share|improve this answer
This seems to me to be barely more than a link to an external site hence might be removed. (Because links may 'die' and it is helpful at least to summarise content from elsewhere so people are not obliged to visit the other site for any detail.) – pnuts Jun 10 '13 at 18:28
I find the comment content to be descriptive enough - it says "FUSE" (Perhaps expanding the acronym would be better); The link is just to an implementation. – aviv Jun 23 '13 at 20:20
FUSE. @aviv Well, answer has not been removed yet, so hopefully no harm done! – pnuts Jun 29 '13 at 23:37
Wasn't aware of short answers problem, answer expanded. Looks like I will have to check back the site for my answers from time to time, in absence of email notifications :) Learnt to use favs, by now. Thanks for the comments. – amontero Jul 7 '13 at 14:17

None of these alias solutions work for git or other programs other than ssh.

I've slapped together a quick-and-dirty, but you might want to improve on it.

Add this to your ~/.bashrc

mkdir -p ~/.ssh/config.d/
[ -e ~/.ssh/config ] && mv ~/.ssh/config ~/.ssh/config.bak.$(date -Ins)
cat ~/.ssh/config.d/* > ~/.ssh/config

Each time you start a session, it'll merge together all the files in ~/.ssh/config.d. (line 3)

The downside with this version is that if you change ~/.ssh/config next session you open your changes would be lost, so to prevent that I move the existing file to a .bak file. (line 2) The problem there is you're gonna have a whole lot of .bak files after a while.

share|improve this answer
Excellent with adding some is_anything_changed condition – vp_arth Jul 4 '15 at 4:57

Starting with ssh 7.3 (which is the next upcoming release as I'm writing this), an Include directive is available.

Include: Include the specified configuration file(s). Multiple path names may be specified and each pathname may contain glob wildcards and shell-like "~" references to user home directories. Files without absolute paths are assumed to be in ~/.ssh. An Include directive may appear inside a Match or Host block to perform conditional inclusion.

(Here is the link to the resolved bug report, that also includes tha patch:

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .