def chown_tty(username)
      tty = `tty 2> /dev/null`.chomp
      @log.error("'tty' command failed") unless $?.success?

      if File.exists?(tty)
        %x(sudo chown #{Shellwords.escape(username)} #{Shellwords.escape(tty)})
        raise RuntimeError, "Failed to change ownership of #{tty}" unless $?.success?
        else
          @log.error("'tty' command did not give a reasonable answer: #{tty}")
      end
    end
def chown_tty(username)
      tty = `tty 2> /dev/null`.chomp
      @log.error("'tty' command failed") unless $?.success?

      if File.exists?(tty)
        %x(sudo chown #{Shellwords.escape(username)} #{Shellwords.escape(tty)})
        raise RuntimeError, "Failed to change ownership of #{tty}" unless $?.success?
        else
          @log.error("'tty' command did not give a reasonable answer: #{tty}")
      end
    end
Ensure the user's PTY/TTY will be owned by him once we thunk through to his account.
 This helps apps like screen/tmux work better.