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, cumulus, 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):



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/beaker/host_prebuilt_steps.rb', line 338

def  host, opts
  logger = opts[:logger]
  block_on host do |host|
    logger.debug "Update /etc/ssh/sshd_config to allow root login"
    # note: this sed command only works on gnu sed
    if host['platform'] =~ /osx/
      host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin no/PermitRootLogin Yes/g' /etc/sshd_config"))
      host.exec(Command.new("sudo sed -i '' 's/#PermitRootLogin yes/PermitRootLogin Yes/g' /etc/sshd_config"))
    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 host['platform'] =~ /debian|ubuntu|cumulus/
      host.exec(Command.new("sudo su -c \"service ssh restart\""), {:pty => true})
    elsif host['platform'] =~ /centos|el-|redhat|fedora|eos/
      host.exec(Command.new("sudo -E /sbin/service sshd reload"), {:pty => true})
    else
      @logger.warn("Attempting to update ssh on non-supported platform: #{host.name}: #{host['platform']}")
    end
  end
end