Net::Netrc(3perl)

✨ Net::Netrc ✨

okay bestie, gather round, because this is the little module that reads your .netrc file so you don't have to hand over your passwords like a chump πŸ’– it lives in the Perl Programmers Reference Guide and it is genuinely so useful, i'm obsessed.


πŸ’… NAME

Net::Netrc β€” an OO interface to users' .netrc file. that's it, that's the vibe. object-oriented, lowkey iconic, no cap. πŸŽ€


🌸 SYNOPSIS

here's the whole vibe in four lines, literally:

use Net::Netrc;

$mach = Net::Netrc->lookup('some.machine');
$login = $mach->login;
($login, $password, $account) = $mach->lpa;

πŸ¦‹ DESCRIPTION

so Net::Netrc is a class that gives you a super simple interface to the .netrc file β€” the same file the ftp program uses. yes, that ftp. the ancient one. it still eats, okay? πŸ‘‘

Net::Netrc also implements security checks exactly like the ftp program does, and bestie, listen up because these matter:

  1. the .netrc file must be owned by the user, and
  2. the ownership permissions should be such that only the owner has read and write access.
if those conditions are not met, a warning is output and the .netrc file is not read. periodt. 🚨

The .netrc File

the .netrc file is where login and initialization info lives for the auto-login process. it resides in the user's home directory. these are the tokens it recognizes β€” and they can be separated by spaces, tabs, or new-lines, so go wild with your whitespace ✨

  • machine name β€” identifies a remote machine name. the auto-login process searches the .netrc file for a machine token that matches the remote machine specified. once a match is made, the subsequent .netrc tokens are processed, stopping when the end of file is reached or another machine or a default token is encountered. slay, that's the whole search algorithm 🫢
  • default β€” this is the same as machine name except that default matches any name. there can be only one default token, and it must be after all machine tokens. normally it's used like this:
default login anonymous password user@site

thereby giving the user automatic anonymous login to machines not specified in .netrc. iconic behaviour honestly πŸ’–

  • login name β€” identifies a user on the remote machine. if this token is present, the auto-login process will initiate a login using the specified name.
  • password string β€” supplies a password. if this token is present, the auto-login process will supply the specified string if the remote server requires a password as part of the login process. πŸ”
  • account string β€” supplies an additional account password. if this token is present, the auto-login process will supply the specified string if the remote server requires an additional account password.
  • macdef name β€” defines a macro. Net::Netrc only parses this field to be compatible with ftp. it does not do anything else with it, bestie, don't get your hopes up πŸ™ˆ

🧚 Class Methods

the constructor for a Net::Netrc object is not called new, because it doesn't really create a new object. instead it's called lookup, because… that's essentially what it does. main character naming energy, honestly πŸ’…

  • lookup($machine[, $login]) β€” lookup and return a reference to the entry for $machine. if $login is given then the entry returned will have the given login. if $login is not given then the first entry in the .netrc file for $machine will be returned.

if a matching entry cannot be found, and a default entry exists, then a reference to the default entry is returned.

if there is no matching entry found and there is no default defined, or no .netrc file is found, then undef is returned. so always check for undef, bestie, i'm begging 😭


🌈 Object Methods

  • login() β€” return the login id for the netrc entry ✨
  • password() β€” return the password for the netrc entry πŸ”
  • account() β€” return the account information for the netrc entry πŸŽ€
  • lpa() β€” return a list of login, password and account information for the netrc entry. three for one, we love a bundle πŸ’–

πŸ“ EXPORTS

None.

as in zero. nothing. she exports nothing and she's not sorry. ⭐


πŸ’€ KNOWN BUGS

see https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=libnet β€” go file things there if something's cursed, bestie πŸ™


πŸ‘‘ SEE ALSO

Net::Cmd.


🩷 AUTHOR

Graham Barr β€” Graham Barr <gbarr@pobox.com>.

Steve Hay β€” Steve Hay <shay@cpan.org> β€” is now maintaining libnet as of version 1.22_02. passing the torch, we love to see it 🫢


Copyright (C) 1995-1998 Graham Barr. All rights reserved.

Copyright (C) 2013-2014, 2020 Steve Hay. All rights reserved.


πŸŽ€ LICENCE

this module is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e. under the terms of either the GNU General Public License or the Artistic License, as specified in the LICENCE file.


⭐ VERSION

Version 3.15.


🌸 DATE

20 March 2023.


πŸ¦‹ HISTORY

see the Changes file.


and that's the whole page, bestie πŸ’– this one's from perl v5.44.0, dated 2026-10-17, and it's the Net::Netrc(3perl) man page β€” read it, love it, keep your .netrc chmod'd correctly or she simply will not read it. no cap. πŸ‘‘βœ¨

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms