Windows PSQL command line: is there a way to allow for passwordless login?

后端 未结 6 1683
星月不相逢
星月不相逢 2020-12-13 07:30

My goal is to be able to fire off a command without having to be prompted for my password. Is there any way to achieve this from the windows command line? In Linux I feel I

6条回答
  •  一向
    一向 (楼主)
    2020-12-13 07:40

    I realize this question is a bit old now, but I believe there is a better means for secure, password-free PostgreSQL logon on Windows - SSPI.

    1. Create a local or domain user account and PostgreSQL login with the same name.

    2. In pg_ident.conf, create a mapping:

      # MAPNAME   SYSTEM-USERNAME      PG-USERNAME
      SSPI        username@AUTHORITY   loginname
      

      Replace username with the Windows user name (this is the sAMAccountName attribute for domain accounts), and replace AUTHORITY with the computer name or short domain name. If you're not sure what to use for AUTHORITY, check the PostgreSQL log file. For a local account, this will be the computer name; for a domain account, it's probably the short domain name. Lastly, replace loginname with the PostgreSQL login name (to reduce confusion, I would recommend using the same name for both username and loginname).

    3. In pg_hba.conf, allow the logon; e.g.:

      # TYPE   DATABASE   USER        ADDRESS        METHOD
      host     all        loginname   127.0.0.1/32   sspi map=SSPI
      host     all        loginname   ::1/128        sspi map=SSPI
      
    4. If a domain account, set a SPN for it; e.g.:

      setspn -S POSTGRES/serverfqdn username
      

    Now you can log onto Windows using the specified username and run psql.exe, etc. without needing a password.

提交回复
热议问题