How to hide password input from terminal in ruby script

One can also use core ruby.

$ ri IO.noecho

 (from ruby core)
 ------------------------------------------------------------------------------
   io.noecho {|io| }
  ------------------------------------------------------------------------------

 Yields self with disabling echo back.

   STDIN.noecho(&:gets)

 will read and return a line without echo back.

For 1.9.3 (and above), this requires you adding require 'io/console' to your code.

require 'io/console'
text = STDIN.noecho(&:gets)

Leave a Comment