Creating a .netrc File for Earthdata Login

A .netrc file is a plain text configuration file used to securely store login credentials for automated authentication. When accessing NASA Earthdata resources, a .netrc file allows seamless authentication without being prompted for your Earthdata Login (EDL) username and password every time.

This guide walks you through how to create and secure your .netrc file to store your EDL credentials.

Key Things to Know

  • The general .netrc format is:

    machine urs.earthdata.nasa.gov
        login your_username
        password your_password

    Example:

    machine urs.earthdata.nasa.gov
        login NSIDCDAACUser
        password IloveNSIDCDAAC

    Important: Never share your .netrc file. Keep this file private and never share it.

  • Set appropriate file permissions to prevent unauthorized access.
  • The .netrc file must be in your Home directory. Use these commands to find your HOME directory location:

    • For UNIX systems:

      echo $HOME
    • For Windows systems:

      echo %HOMEDRIVE%%HOMEPATH%

    Create your .netrc file (or _netrc on Windows) in the directory indicated by the command output.

Instructions by Operating System

Unix/Linux/macOS

1.   Open a command line terminal and use the following touch command to create an empty file:

touch ~/.netrc

2.   Set file permissions to restrict access:

chmod 0600 ~/.netrc

This step is crucial. It makes the file readable and writable only by you. If the permissions are too permissive, many tools will refuse to use the file.

3. Then, use the following echo command to store your EDL credentials. Replace the placeholders your_username and your_password with your actual login and password.

echo 'machine urs.earthdata.nasa.gov login your_username password your_password' >> ~/.netrc

4.   You can check the contents of your .netrc file

cat ~/.netrc

Windows

1.  Open a PowerShell session and create a $HOME environment variable using the following command:

[Environment]::SetEnvironmentVariable("HOME", $env:USERPROFILE, "User")

2.  Create a new empty _netrc file using the New-Item command, and then set file permissions using the icacls command:

New-Item -Path "$HOME/_netrc" -ItemType File
icacls "$HOME\_netrc" /inheritance:r /grant:r "${env:USERNAME}:F"

3.  Then, use the Add-Content command to append your credentials to the file. Replace the placeholders your_username and your_password with your actual login and password.

Add-Content -Path "$HOME\_netrc" -Value 'machine urs.earthdata.nasa.gov login your_username password your_password' -Encoding ASCII

4.  If your username or password contain special characters, such as $ or , you may need to add your EDL credentials manually. You can open and edit the _netrc file in notepad by running the command:

notepad "$HOME\_netrc"

Note: If manually editing or creating your _netrc in Notepad or any text editor, ensure it still follows the .netrc format shown above.