Setup Admin User and Privileges
Pigsty uses an operating system administration account with SSH and sudo access to every managed node. The account must be able to log in through SSH and run sudo commands on these nodes. Passwordless access is the standard configuration; password prompts are also supported.
User
Use an account name such as dba or admin.
Avoid root and postgres:
- You can deploy as
root, but this is not recommended for production. - Do not use
postgres(pg_dbsu) as the administration account.
Passwordless
You can enter passwords for each ssh and sudo command instead of configuring passwordless access.
When you run playbooks, use -k|--ask-pass for the SSH password prompt.
Use -K|--ask-become-pass for the sudo password prompt:
If your security policy prohibits passwordless ssh or sudo, use these options.
You can also configure a longer sudo password cache time in sudoers to reduce repeated prompts.
Create Admin User
Your server or virtual machine provider usually creates an initial administration account. If you need a different account, the deployment playbook can create one.
Use an existing administration account or root access to create the new account:
The existing account creates a dedicated dba account with UID 88 by default.
The playbook also configures sudo and SSH access.
These parameters control the account:
| Name | Description | Default |
|---|---|---|
node_admin_enabled | Enable node admin user | true |
node_admin_uid | Node admin user UID | 88 |
node_admin_username | Node admin username | dba |
Sudo
Give the administration account sudo access on every managed node.
Passwordless sudo is recommended.
For an account named vagrant, create or edit its sudoers file:
For the dba account, use this content in /etc/sudoers.d/dba:
If your security policy prohibits passwordless sudo, remove NOPASSWD::
Ansible uses sudo to run commands with root privileges on managed nodes.
If an environment has no sudo, install it first.
This can apply to Docker containers.
SSH
The current local account should have passwordless SSH access to the administration account on every managed node. The local and remote account names can differ. The following procedures describe the basic SSH configuration.
Generate SSH Key
If you do not have an SSH key pair, generate one:
The bootstrap script also generates a key pair if none exists.
Copy SSH Key
Copy the public key to the administration account’s ~/.ssh/authorized_keys file on every node, including the local node.
Use ssh-copy-id:
Using Alias
If a node requires a jumpserver, another port, or different credentials, define an SSH alias in ~/.ssh/config:
Set ansible_host to this SSH alias in the inventory:
Ansible can also use SSH connection parameters directly. See the Ansible Inventory Guide.
This method supports private nodes behind jumpservers and nodes with different ports or credentials. It also lets you use a local laptop as the administration node.
Check Accessibility
From the administration node, the current account should reach every managed node through passwordless ssh.
The remote administration account should also have passwordless sudo access.
Run this command from the administration node for each managed node:
If the command returns without a password prompt or error, passwordless SSH and sudo access work.
Firewall
For production, configure the firewall to block unauthorized access to service ports. By default, block inbound access from office and Internet networks except these ports:
22for SSH node access.80for HTTP and443for HTTPS Web UI access.5432for PostgreSQL access.
If clients use other PostgreSQL service ports, permit those ports as required. See the complete port list.
5432: PostgreSQL database.6432: PgBouncer connection pooler.5433: PostgreSQL primary service.5434: PostgreSQL replica service.5436: PostgreSQL default service.5438: PostgreSQL offline service.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)