To use the psql client remotely on *nix, you can create a password file on the client side and add the comment block shown below to it.
By default, psql looks for a password file named .pgpass in your client side user account to resolve CLI parameters to a unique line in the file. You need to set the file permissions appropriately; and optionally, you can change the location/name of the file using the PGPASSFILE environment variable.
The Usage section provides a few examples of using the psql tool with various CLI parameters. The parameters are used to find a unique line in the file which then provides the remaining parameters, including the password.
The Configuration section provide the syntax for each line.
The block below includes a couple of dummy examples (myhostname1, etc.) that you must replace with your own entries, of course.
/home/myusername/.pgpass
# File: /home/myusername/.pgpass
# chmod 600 /home/myusername/.pgpass
# export PGPASSFILE=/home/myusername/.pgpass
#
# Usage:
# psql -h myremotehostname -U postgres -d postgres
# psql -h myremotehostname -U postgres -d mydbname
# psql -h myremotehostname -U myremoteusername -d mydbname
# psql -h myremotehostname -U myremoteusername
#
# Configuration:
# hostname:port:database:username:password
#
myhostname1:myport1:mydatabase1:myusername1:mypassword1
myhostname2:myport2:mydatabase2:myusername2:mypassword2