Method: Beaker::HostPrebuiltSteps#enable_root_login

Defined in:
lib/beaker/host_prebuilt_steps.rb

#enable_root_login(host, opts) ⇒ Object

Update sshd_config on debian, ubuntu, centos, el, redhat and fedora boxes to allow for root login

Does nothing on other platfoms.

Parameters:

  • host (Host, Array<Host>)

    One or more hosts to act upon

  • opts (Hash{Symbol=>String})

    Options to alter execution.

Options Hash (opts):



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/beaker/host_prebuilt_steps.rb', line 301

def  host, opts
  logger = opts[:logger]
  block_on host do |host|
    logger.debug "Update sshd_config to allow root login"
    if host['platform'].include?('osx')
      # If osx > 10.10 use '/private/etc/ssh/sshd_config', else use '/etc/sshd_config'
      ssh_config_file = '/private/etc/ssh/sshd_config'
      ssh_config_file = '/etc/sshd_config' if /^osx-10\.(9|10)/i.match?(host['platform'])

      host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin no/PermitRootLogin Yes/g' #{ssh_config_file}"))
      host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin yes/PermitRootLogin Yes/g' #{ssh_config_file}"))
    elsif host['platform'].include?('freebsd')
      host.exec(Command.new("sudo sed -i -e 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), { :pty => true })
    elsif host['platform'].include?('openbsd')
      host.exec(Command.new("sudo perl -pi -e 's/^PermitRootLogin no/PermitRootLogin yes/' /etc/ssh/sshd_config"), { :pty => true })
    elsif host['platform'].include?('solaris-10')
      host.exec(Command.new("sudo gsed -i -e 's/#PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), { :pty => true })
    elsif host['platform'].include?('solaris-11')
      host.exec(Command.new("if grep \"root::::type=role\" /etc/user_attr; then sudo rolemod -K type=normal root; else echo \"root user already type=normal\"; fi"), { :pty => true })
      host.exec(Command.new("sudo gsed -i -e 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config"), { :pty => true })
    elsif host.is_powershell?
      logger.warn("Attempting to enable root login non-supported platform: #{host.name}: #{host['platform']}")
    elsif host.is_cygwin?
      host.exec(Command.new("sed -ri 's/^#?PermitRootLogin /PermitRootLogin yes/' /etc/sshd_config"), { :pty => true })
    else
      host.exec(Command.new("sudo su -c \"sed -ri 's/^#?PermitRootLogin no|^#?PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config\""), { :pty => true })
    end
    # restart sshd
    if /debian|ubuntu/.match?(host['platform'])
      host.exec(Command.new("sudo su -c \"service ssh restart\""), { :pty => true })
    elsif /(el|centos|redhat|oracle|scientific)-[0-6]\b/.match?(host['platform'])
      host.exec(Command.new("sudo -E /sbin/service sshd reload"), { :pty => true })
    elsif /amazon|arch|centos|el|redhat|fedora/.match?(host['platform'])
      host.exec(Command.new("sudo -E systemctl restart sshd.service"), { :pty => true })
    elsif /(free|open)bsd/.match?(host['platform'])
      host.exec(Command.new("sudo /etc/rc.d/sshd restart"))
    elsif host['platform'].include?('solaris')
      host.exec(Command.new("sudo -E svcadm restart network/ssh"), { :pty => true })
    else
      logger.warn("Attempting to update ssh on non-supported platform: #{host.name}: #{host['platform']}")
    end
  end
end