4 Replies Latest reply on Oct 10, 2005 4:29 PM by Gerald McCollam

    I want to parse and add entry to the /etc/ssh_config file.

    Maria Cabral

      I am parsing and writing entry to the /etc/ssh_config file using BLPackage. However, I got into this issue.

      /etc/ssh_config has:

      Host *

      ForwardX11 yes

       

      I want to add this entry:

      Protocol 2

       

      If I add entry without considering that Host is a header it would be:

      Host *

      ForwardX11 yes

      Protocol 2

       

      How does ssh_config treats “Host *” entry? Is the Host * entry a parent and everything else is the child?

       

      Message was edited by:

      Maria Cabral

        • 1. Re: I want to parse and add entry to the /etc/ssh_config file.

          Unfortunately, formatting of data in these posts gets lost unless you use the "pre" option. The situation is that ssh_config contains headers, followed by name/value pairs which are separated by spaces. An example of this is the following:

           

          Host *
          ForwardX11 yes

           

          I believe Maria wants to add the "Protocol 2" entry underneath the "Host *" section, so that the file would now look like:

           

          Host *
          ForwardX11 yes
          Protocol 2

           

          The best we can get the file to look like with the current grammars is the following:

          Host *
          ForwardX11 yes
          Protocol 2

           

          We assume that this is wrong, since we assume that ssh is parsing this file and assuming that any entry not indented is a section header (if this assumption is wrong, please let us know).

           

          The key to the entry showing up indented like it should be (and as is denoted above) is being able to decipher a config header section from a config entry. In the case of windows .ini files, the header is always denoted by left and right brackets ( , respectively), so the ini grammar can account for this. But what if the section is only denoted by indentation, or in this case, a lack of indentation? Any ideas on how can we account for this in a grammar?

          • 2. Re: I want to parse and add entry to the /etc/ssh_config file.

            The ssh_config file doesn't care whether there is an indentation before lines below the HOST header. So,

             

            Host *
            ForwardX11 yes
            Protocol 2

             

            is no different than

             

            Host *
            ForwardX11yes
            Protocol2

             

             

            As to Maria's original question, the Host line binds the lines below it to the server referenced in Host until the next Host line is seen. So, you can have the following:

             

            Host 10.1.1.1

            ForwardX11 yes

            Host 10.1.1.2

            ForwardX11 no <- only affects 10.1.1.2.

             

            Sung Koo

             

             

             



             

             

             

             

            Message was edited by:

            Sung Koo

            • 3. Re: I want to parse and add entry to the /etc/ssh_config file.

              Great. So it sounds like any line beginning with the word "Host" should be considered a header and all of its children are simple name/value pairs (separated by whitespace). Should be easy enough to write a grammar for it.

              • 4. Re: I want to parse and add entry to the /etc/ssh_config file.

                Hi Maria,

                 

                The usage 'host *' will restrict the configuration options that follow it up to the next 'host' declaration, for any client.

                 

                For example:

                 

                1. ------ START secure hosts -----

                Host

                PasswordPromptHost yes

                PasswordPromptLogin yes

                RhostsAuthentication no

                RhostsRSAAuthentication yes

                StrictHostKeyChecking ask

                1. ------ END secure hosts -----

                 

                1. --- BEGIN all hosts ----

                Host *

                RhostsAuthentication no

                1. --- END all hosts ----

                 

                Hope this helps.

                 

                - gerald