ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Patching configuration files

    IT Discussion
    linux patching configuration
    7
    12
    1.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • 1
      1337 @travisdh1
      last edited by 1337

      @travisdh1 said in Patching configuration files:

      @Pete-S That is what things like salt and Ansible are for. You tell the main server what programs should be installed/running, and config files. It manages the servers for you from there.

      Yes, I know and it's a good point. However I need something better than manual editing for servers that are not hooked up to ansible or salt.

      JaredBuschJ 1 Reply Last reply Reply Quote 0
      • JaredBuschJ
        JaredBusch @1337
        last edited by

        @Pete-S said in Patching configuration files:

        I need something better than manual editing for servers that are not hooked up to ansible or salt.

        add them to salt/ansible.

        1 1 Reply Last reply Reply Quote 3
        • 1
          1337 @JaredBusch
          last edited by 1337

          @JaredBusch said in Patching configuration files:

          @Pete-S said in Patching configuration files:

          I need something better than manual editing for servers that are not hooked up to ansible or salt.

          add them to salt/ansible.

          You're right. It seems like that is easier than trying to figure out how to use diff & patch.

          scottalanmillerS 1 Reply Last reply Reply Quote 0
          • scottalanmillerS
            scottalanmiller @1337
            last edited by

            @Pete-S said in Patching configuration files:

            @JaredBusch said in Patching configuration files:

            @Pete-S said in Patching configuration files:

            I need something better than manual editing for servers that are not hooked up to ansible or salt.

            add them to salt/ansible.

            You're right. It seems like that is easier than trying to figure out how to use diff & patch.

            For sure, that's what I was thinking, too.

            1 Reply Last reply Reply Quote 0
            • M
              manxam
              last edited by

              Create a shell script that just runs sed on the files you need?

              #!/bin/sh
              sed -i 's/PermitRootLogin No/PermitRootLogin Yes/' /etc/sshd_config
              sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/sshd_config
              
              IRJI 1 Reply Last reply Reply Quote 1
              • IRJI
                IRJ @manxam
                last edited by

                @manxam said in Patching configuration files:

                Create a shell script that just runs sed on the files you need?

                #!/bin/sh
                sed -i 's/PermitRootLogin No/PermitRootLogin Yes/' /etc/sshd_config
                sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/sshd_config
                

                Yeah using sed is the answer if you want to add or remove a few lines.

                1 Reply Last reply Reply Quote 0
                • 1
                  1337
                  last edited by

                  Contextual patching is the answer to my question. It will look at the lines before and after each change so it can apply a patch even if the location inside the file is not the same.

                  # compare files and find what out what has changed
                  diff -c oldfile newfile > changes.patch
                  
                  # apply the same patch to another file
                  patch -i changes.patch anotherfile
                  

                  You can also diff & patch entire directory trees in one command.
                  For example all the files under /etc/

                  M 1 Reply Last reply Reply Quote 0
                  • M
                    manxam @1337
                    last edited by

                    @Pete-S : Does that not rely on always having the same context around the lines to patch though?
                    I.E. You will always have to have PasswordAuthentication directly preceding PermitRootLogin followed by RandomBlockOfText in order to find and patch PermitRootLogin?
                    I may be wrong, but I thought that if you added another config entry between PasswordAuthentication and PermitRootLogin that the patch would fail.

                    1 1 Reply Last reply Reply Quote 0
                    • 1
                      1337 @manxam
                      last edited by

                      @manxam said in Patching configuration files:

                      @Pete-S : Does that not rely on always having the same context around the lines to patch though?
                      I.E. You will always have to have PasswordAuthentication directly preceding PermitRootLogin followed by RandomBlockOfText in order to find and patch PermitRootLogin?
                      I may be wrong, but I thought that if you added another config entry between PasswordAuthentication and PermitRootLogin that the patch would fail.

                      I'm not sure exactly what happens. I may have to run some tests to see.

                      1 Reply Last reply Reply Quote 0
                      • stacksofplatesS
                        stacksofplates
                        last edited by

                        Yeah this is bread and butter for config management tools. You'd either use a template for the config or the lineinfile module for Ansible.

                        Your template would have something like this:

                        PermitRootLogin {{ root_login_enabled }}
                        

                        In it and then you can control which servers allow root login with the root_login_enabled variable.

                        1 Reply Last reply Reply Quote 2
                        • 1 / 1
                        • First post
                          Last post