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