Dynamic ~/.ssh/config












1















I'd like make my ~/.ssh/config file dynamically generated by a shell script (or anything else that prints to STDOUT).



Is there a UNIX trick to make reading a file result in executing a command & reading it's STDOUT?



What I'd like:



#!/bin/bash
echo "Hello World"

$ cat myfile
Hello World









share|improve this question


















  • 1





    This would only possible be possible with a self-written filesystem, e.g. via FUSE, or depending on the ssh implementation with FIFOs. Maybe the -F flag of ssh which allows to pass an alternative user-config file helps you. You can also replace ssh with an wrapper script, which sets the config file before running the actual ssh.

    – jofel
    Dec 2 '14 at 14:58













  • A colleague sent me this: github.com/markhellewell/sshconfigfs (which is an implementation of the FUSE idea)

    – Daniel Upton
    Dec 2 '14 at 15:16






  • 1





    This smells like the XY problem. Maybe if you explained why you want to do such a thing, there's a better way to accomplish it.

    – Kenster
    Dec 4 '14 at 20:39











  • Having a read of a file, trigger an execution of a program, can be dangerous. The execution would have to be done by the user that set it up, not the user that read the file. The program would therefore not have access to anything that the creator would not otherwise have access to.

    – ctrl-alt-delor
    Mar 7 '15 at 18:45
















1















I'd like make my ~/.ssh/config file dynamically generated by a shell script (or anything else that prints to STDOUT).



Is there a UNIX trick to make reading a file result in executing a command & reading it's STDOUT?



What I'd like:



#!/bin/bash
echo "Hello World"

$ cat myfile
Hello World









share|improve this question


















  • 1





    This would only possible be possible with a self-written filesystem, e.g. via FUSE, or depending on the ssh implementation with FIFOs. Maybe the -F flag of ssh which allows to pass an alternative user-config file helps you. You can also replace ssh with an wrapper script, which sets the config file before running the actual ssh.

    – jofel
    Dec 2 '14 at 14:58













  • A colleague sent me this: github.com/markhellewell/sshconfigfs (which is an implementation of the FUSE idea)

    – Daniel Upton
    Dec 2 '14 at 15:16






  • 1





    This smells like the XY problem. Maybe if you explained why you want to do such a thing, there's a better way to accomplish it.

    – Kenster
    Dec 4 '14 at 20:39











  • Having a read of a file, trigger an execution of a program, can be dangerous. The execution would have to be done by the user that set it up, not the user that read the file. The program would therefore not have access to anything that the creator would not otherwise have access to.

    – ctrl-alt-delor
    Mar 7 '15 at 18:45














1












1








1


1






I'd like make my ~/.ssh/config file dynamically generated by a shell script (or anything else that prints to STDOUT).



Is there a UNIX trick to make reading a file result in executing a command & reading it's STDOUT?



What I'd like:



#!/bin/bash
echo "Hello World"

$ cat myfile
Hello World









share|improve this question














I'd like make my ~/.ssh/config file dynamically generated by a shell script (or anything else that prints to STDOUT).



Is there a UNIX trick to make reading a file result in executing a command & reading it's STDOUT?



What I'd like:



#!/bin/bash
echo "Hello World"

$ cat myfile
Hello World






bash ssh files stdout






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 2 '14 at 14:44









Daniel UptonDaniel Upton

150115




150115








  • 1





    This would only possible be possible with a self-written filesystem, e.g. via FUSE, or depending on the ssh implementation with FIFOs. Maybe the -F flag of ssh which allows to pass an alternative user-config file helps you. You can also replace ssh with an wrapper script, which sets the config file before running the actual ssh.

    – jofel
    Dec 2 '14 at 14:58













  • A colleague sent me this: github.com/markhellewell/sshconfigfs (which is an implementation of the FUSE idea)

    – Daniel Upton
    Dec 2 '14 at 15:16






  • 1





    This smells like the XY problem. Maybe if you explained why you want to do such a thing, there's a better way to accomplish it.

    – Kenster
    Dec 4 '14 at 20:39











  • Having a read of a file, trigger an execution of a program, can be dangerous. The execution would have to be done by the user that set it up, not the user that read the file. The program would therefore not have access to anything that the creator would not otherwise have access to.

    – ctrl-alt-delor
    Mar 7 '15 at 18:45














  • 1





    This would only possible be possible with a self-written filesystem, e.g. via FUSE, or depending on the ssh implementation with FIFOs. Maybe the -F flag of ssh which allows to pass an alternative user-config file helps you. You can also replace ssh with an wrapper script, which sets the config file before running the actual ssh.

    – jofel
    Dec 2 '14 at 14:58













  • A colleague sent me this: github.com/markhellewell/sshconfigfs (which is an implementation of the FUSE idea)

    – Daniel Upton
    Dec 2 '14 at 15:16






  • 1





    This smells like the XY problem. Maybe if you explained why you want to do such a thing, there's a better way to accomplish it.

    – Kenster
    Dec 4 '14 at 20:39











  • Having a read of a file, trigger an execution of a program, can be dangerous. The execution would have to be done by the user that set it up, not the user that read the file. The program would therefore not have access to anything that the creator would not otherwise have access to.

    – ctrl-alt-delor
    Mar 7 '15 at 18:45








1




1





This would only possible be possible with a self-written filesystem, e.g. via FUSE, or depending on the ssh implementation with FIFOs. Maybe the -F flag of ssh which allows to pass an alternative user-config file helps you. You can also replace ssh with an wrapper script, which sets the config file before running the actual ssh.

– jofel
Dec 2 '14 at 14:58







This would only possible be possible with a self-written filesystem, e.g. via FUSE, or depending on the ssh implementation with FIFOs. Maybe the -F flag of ssh which allows to pass an alternative user-config file helps you. You can also replace ssh with an wrapper script, which sets the config file before running the actual ssh.

– jofel
Dec 2 '14 at 14:58















A colleague sent me this: github.com/markhellewell/sshconfigfs (which is an implementation of the FUSE idea)

– Daniel Upton
Dec 2 '14 at 15:16





A colleague sent me this: github.com/markhellewell/sshconfigfs (which is an implementation of the FUSE idea)

– Daniel Upton
Dec 2 '14 at 15:16




1




1





This smells like the XY problem. Maybe if you explained why you want to do such a thing, there's a better way to accomplish it.

– Kenster
Dec 4 '14 at 20:39





This smells like the XY problem. Maybe if you explained why you want to do such a thing, there's a better way to accomplish it.

– Kenster
Dec 4 '14 at 20:39













Having a read of a file, trigger an execution of a program, can be dangerous. The execution would have to be done by the user that set it up, not the user that read the file. The program would therefore not have access to anything that the creator would not otherwise have access to.

– ctrl-alt-delor
Mar 7 '15 at 18:45





Having a read of a file, trigger an execution of a program, can be dangerous. The execution would have to be done by the user that set it up, not the user that read the file. The program would therefore not have access to anything that the creator would not otherwise have access to.

– ctrl-alt-delor
Mar 7 '15 at 18:45










1 Answer
1






active

oldest

votes


















0














The true question is: Why do you need dynamic configuration (and thus how to avoid having to generate configuration dynamically).




Is there a UNIX trick to make reading a file result in executing a command & reading it's STDOUT?




Bash has a feature that does exactly that, it's named "Process Substitution" :



ssh -F <( echo "Host *"; echo " User dummy" ) ssh.example.com


Unfortunately, it won't work with openssh's ssh, as it dies with error:



Can't open user config file /dev/fd/63: No such file or directory



Also, some people seems to use complex scheme to use a FIFO file, like Multiple SSH client configuration files, but eventually they use an alias, and that can be simplified with something like :



alias ssh = '~/bin/gen_ssh_config.sh > /tmp/XX; ssh -F /tmp/XX'





share|improve this answer
























  • If you use zsh instead of bash, you can use the =(...) form of process substitution that uses temp files instead of pipes and /dev/fd: ssh -F =(echo "Host *"; echo " User dummy") ssh.example.com

    – Stéphane Chazelas
    Mar 10 '16 at 15:21











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f171061%2fdynamic-ssh-config%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The true question is: Why do you need dynamic configuration (and thus how to avoid having to generate configuration dynamically).




Is there a UNIX trick to make reading a file result in executing a command & reading it's STDOUT?




Bash has a feature that does exactly that, it's named "Process Substitution" :



ssh -F <( echo "Host *"; echo " User dummy" ) ssh.example.com


Unfortunately, it won't work with openssh's ssh, as it dies with error:



Can't open user config file /dev/fd/63: No such file or directory



Also, some people seems to use complex scheme to use a FIFO file, like Multiple SSH client configuration files, but eventually they use an alias, and that can be simplified with something like :



alias ssh = '~/bin/gen_ssh_config.sh > /tmp/XX; ssh -F /tmp/XX'





share|improve this answer
























  • If you use zsh instead of bash, you can use the =(...) form of process substitution that uses temp files instead of pipes and /dev/fd: ssh -F =(echo "Host *"; echo " User dummy") ssh.example.com

    – Stéphane Chazelas
    Mar 10 '16 at 15:21
















0














The true question is: Why do you need dynamic configuration (and thus how to avoid having to generate configuration dynamically).




Is there a UNIX trick to make reading a file result in executing a command & reading it's STDOUT?




Bash has a feature that does exactly that, it's named "Process Substitution" :



ssh -F <( echo "Host *"; echo " User dummy" ) ssh.example.com


Unfortunately, it won't work with openssh's ssh, as it dies with error:



Can't open user config file /dev/fd/63: No such file or directory



Also, some people seems to use complex scheme to use a FIFO file, like Multiple SSH client configuration files, but eventually they use an alias, and that can be simplified with something like :



alias ssh = '~/bin/gen_ssh_config.sh > /tmp/XX; ssh -F /tmp/XX'





share|improve this answer
























  • If you use zsh instead of bash, you can use the =(...) form of process substitution that uses temp files instead of pipes and /dev/fd: ssh -F =(echo "Host *"; echo " User dummy") ssh.example.com

    – Stéphane Chazelas
    Mar 10 '16 at 15:21














0












0








0







The true question is: Why do you need dynamic configuration (and thus how to avoid having to generate configuration dynamically).




Is there a UNIX trick to make reading a file result in executing a command & reading it's STDOUT?




Bash has a feature that does exactly that, it's named "Process Substitution" :



ssh -F <( echo "Host *"; echo " User dummy" ) ssh.example.com


Unfortunately, it won't work with openssh's ssh, as it dies with error:



Can't open user config file /dev/fd/63: No such file or directory



Also, some people seems to use complex scheme to use a FIFO file, like Multiple SSH client configuration files, but eventually they use an alias, and that can be simplified with something like :



alias ssh = '~/bin/gen_ssh_config.sh > /tmp/XX; ssh -F /tmp/XX'





share|improve this answer













The true question is: Why do you need dynamic configuration (and thus how to avoid having to generate configuration dynamically).




Is there a UNIX trick to make reading a file result in executing a command & reading it's STDOUT?




Bash has a feature that does exactly that, it's named "Process Substitution" :



ssh -F <( echo "Host *"; echo " User dummy" ) ssh.example.com


Unfortunately, it won't work with openssh's ssh, as it dies with error:



Can't open user config file /dev/fd/63: No such file or directory



Also, some people seems to use complex scheme to use a FIFO file, like Multiple SSH client configuration files, but eventually they use an alias, and that can be simplified with something like :



alias ssh = '~/bin/gen_ssh_config.sh > /tmp/XX; ssh -F /tmp/XX'






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 '15 at 18:16









Franklin PiatFranklin Piat

1,8941828




1,8941828













  • If you use zsh instead of bash, you can use the =(...) form of process substitution that uses temp files instead of pipes and /dev/fd: ssh -F =(echo "Host *"; echo " User dummy") ssh.example.com

    – Stéphane Chazelas
    Mar 10 '16 at 15:21



















  • If you use zsh instead of bash, you can use the =(...) form of process substitution that uses temp files instead of pipes and /dev/fd: ssh -F =(echo "Host *"; echo " User dummy") ssh.example.com

    – Stéphane Chazelas
    Mar 10 '16 at 15:21

















If you use zsh instead of bash, you can use the =(...) form of process substitution that uses temp files instead of pipes and /dev/fd: ssh -F =(echo "Host *"; echo " User dummy") ssh.example.com

– Stéphane Chazelas
Mar 10 '16 at 15:21





If you use zsh instead of bash, you can use the =(...) form of process substitution that uses temp files instead of pipes and /dev/fd: ssh -F =(echo "Host *"; echo " User dummy") ssh.example.com

– Stéphane Chazelas
Mar 10 '16 at 15:21


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f171061%2fdynamic-ssh-config%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?