p0cli: scp: Troubleshooting

Last updated: May 2, 2025

Troubleshooting Guide: p0 scp

When copying files with p0 scp, you may encounter errors related to authentication, host identification, network connectivity, SSH key provisioning, or the underlying scp process. Use this guide to diagnose and resolve common issues.


1. Authentication & Authorization Failures

Error Message

Cause

Resolution

Please run 'p0 login <organization>' to use the P0 CLI.

Not logged in or session expired.

Run p0 login <your-org-slug> and complete the OIDC flow.

Could not load credentials for "<name>"

Corrupt or expired credential cache.

Remove ~/.p0/identity-cache, then re-run p0 login.

Silent hang or immediate exit without output

Automatic token refresh failed.

Manually clear credentials (p0 logout or delete ~/.p0/identity.json), then log in again.


2. Host & Argument Validation

Symptom / Message

Cause

Resolution

Exactly one host (source or destination) must be remote.

Both or neither argument uses <hostname>: syntax.

Prefix exactly one of source or destination with <hostname>:.

Could not determine host identifier from source or destination

Malformed <hostname>:<path> (missing or extra colon).

Ensure exactly one colon with no spaces, e.g., prod-db:/var/backups/file.sql.

Azure SSH does not currently support specifying a port…

You passed -P or -p flags with --provider azure.

Remove port flags; Azure integration only works on default port 22.


3. Network & Connectivity Issues

Error Message

Cause

Resolution

Network error: Unable to reach the server at https://…/command/.

Cannot connect to P0’s API (DNS, proxy, firewall).

- Verify internet access and DNS.- Check appUrl in ~/.p0/config.json.- Whitelist the endpoint.

Underlying scp hangs or times out

SSH port blocked or host unreachable.

- Ensure network access to the remote host on port 22.- Confirm the hostname via P0’s session list.


4. Provisioning & SSH Key Issues

Symptom / Message

Cause

Resolution

No prompt, then SSH authentication failure

P0 failed to obtain or write the temporary private key.

- Run with --debug to see provisioning logs.- Check file permissions in $HOME/.ssh.

Permission denied (publickey)

Remote host doesn’t accept the P0-issued key.

- Confirm the host is managed by P0 SSH integration.- Verify the Linux username mapping.


5. Underlying scp Errors

Error Message

Cause

Resolution

scp: command not found

No scp binary installed.

Install OpenSSH client (openssh-client on Linux).

Permission denied (writing file)

Local filesystem permissions issue.

Check directory permissions; ensure you have write access and sufficient disk space.

No such file or directory

Remote path doesn’t exist.

Verify remote path is correct and parent directories exist.


6. Debugging & Logs

  • Enable P0 debug

p0 scp --debug <source> <destination>
  • Shows API calls, key issuance, and provisioning messages.

  • Enable CLI debug

P0_CLI_DEBUG=true p0 scp <source> <destination>
  • Prints low-level HTTP request/response details.

  • Inspect raw provisioning

    In debug mode, note the path to the temporary private key and try a manual:

scp -i /path/to/temp_key <source> <destination>
  • to isolate SSH vs. provisioning errors.


7. Tips & Best Practices

  • Use --reason for audit trails, especially when using --sudo.

  • Quote paths with spaces:

p0 scp "prod-web:/var/www/My Site/index.html" ./
  • Combine flags correctly:

    • P0 options before --

    • scp options after --

p0 scp --recursive ./dir prod-app:/opt/app/ -- -C -P 2222
  • Confirm valid SSH destinations before copying:

p0 ls ssh session destination --size 10
  • Ensures your target hostname exists in P0’s session destinations.

  • Automate with debug when iterating:

p0 scp --debug ./file.txt my-host:/tmp/

If you encounter an issue not covered here, please gather:

  1. The exact p0 scp command you ran

  2. Full stderr output (including debug logs)

  3. Results of p0 ls ssh session destination --size 10 for your hostname

Then contact your P0 support team for further assistance.