Sha256: 608882caaf7c0baa57c7f982b47e07c5a57b5643604b21c77e2084d2ec33bd2c

Contents?: true

Size: 1.2 KB

Versions: 43

Compression:

Stored size: 1.2 KB

Contents

module Incline
  class CLI
    class Prepare
      
      private
      
      def config_ssh(shell)
        pa_rex = /#\s*PubkeyAuthentication\s+[^\n]*\n/
        rl_rex = /#\s*PermitRootLogin\s+[^\n]*\n/

        shell.with_stat('Configuring SSH') do
          shell.sudo_exec "cp -f /etc/ssh/sshd_config #{shell.home_path}/tmp_sshd_conf"
          contents = shell.read_file("#{shell.home_path}/tmp_sshd_conf")
          new_contents = contents.gsub(pa_rex, "PubkeyAuthentication yes\n").gsub(rl_rex, "PermitRootLogin no\n")
          if new_contents != contents
            shell.write_file "#{shell.home_path}/tmp_sshd_conf", new_contents
            shell.sudo_exec "chown root:root #{shell.home_path}/tmp_sshd_conf"
            shell.sudo_exec "chmod 600 #{shell.home_path}/tmp_sshd_conf"
            shell.sudo_exec "mv -f #{shell.home_path}/tmp_sshd_conf /etc/ssh/sshd_config"
            
            begin
              shell.sudo_exec_ignore_code 'systemctl restart sshd.service'
            rescue
              # ignore any errors from the SSH restart since we should be exiting the SSH session immediately after this gets executed anyway.
            end
          end
        end
      end
      
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
incline-0.3.14 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.13 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.12 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.11 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.10 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.9 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.8 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.7 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.6 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.5 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.4 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.3 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.2 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.1 lib/incline/cli/prepare/config_ssh.rb
incline-0.3.0 lib/incline/cli/prepare/config_ssh.rb
incline-0.2.36 lib/incline/cli/prepare/config_ssh.rb
incline-0.2.35 lib/incline/cli/prepare/config_ssh.rb
incline-0.2.34 lib/incline/cli/prepare/config_ssh.rb
incline-0.2.28 lib/incline/cli/prepare/config_ssh.rb
incline-0.2.27 lib/incline/cli/prepare/config_ssh.rb