By adding two simple files in your home directory, you can access netCDF files with e.g. Python and Matlab via OPeNDAP without the need to put your credentials in the script.
Note: the domain is the part of the url right behind http(s):// until the next / (see also the examples in the links mentioned below).
It's obvious that you should be conscious of the fact that the .netrc file contains your password in plain text. Don't do this on a public or shared PC.