Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Etc.getlogin

getlogin → String

Returns the short user name of the currently logged in user. Unfortunately, it is often rather easy to fool ::getlogin.

Avoid ::getlogin for security-related purposes.

If ::getlogin fails, try ::getpwuid.

See the unix manpage for getpwuid(3) for more detail.

e.g.

Etc.getlogin -> 'guest'
See also .getgrnam .getpwent .getgrgid .getpwnam also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0