# p0 scp

#### **1. Authentication & Authorization Failures** <a href="#id-1-authentication-and-authorization-failures" id="id-1-authentication-and-authorization-failures"></a>

| **Error Message**                                        | **Cause**                                              | **Resolution**                                                            |
| -------------------------------------------------------- | ------------------------------------------------------ | ------------------------------------------------------------------------- |
| Please run 'p0 login \<organization>' to use the P0 CLI. | You aren’t logged in or your identity file is missing. | Execute `p0 login <ORG ID>` and complete the OIDC flow.                   |
| Could not load credentials for "\<name>"                 | Corrupt or expired credential cache.                   | Remove the cache directory (`rm -rf ~/.p0/cache`) and re-run `p0 login`   |
| Silent hang or immediate exit without output             | Token auto-refresh failed but no explicit error.       | Clear credentials (p0 logout or delete `identity.json`) and log in again. |

***

#### **2. Host & Argument Validation** <a href="#id-2-host-and-argument-validation" id="id-2-host-and-argument-validation"></a>

| **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** <a href="#id-3-network-and-connectivity-issues" id="id-3-network-and-connectivity-issues"></a>

| **Error Message**                                                 | **Cause**                                         | **Resolution**                                                                                      |
| ----------------------------------------------------------------- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| Network error: Unable to reach the server at https\://…/command/. | Can't connect to P0's API (DNS, proxy, firewall). | - Verify internet access and DNS.- Check appUrl in \~/.p0/config.json.- Allowlist 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** <a href="#id-4-provisioning-and-ssh-key-issues" id="id-4-provisioning-and-ssh-key-issues"></a>

| **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 that P0 manages the host via SSH integration.- Verify the Linux username mapping. |

***

#### **5. Underlying scp Errors** <a href="#id-5-underlying-scp-errors" id="id-5-underlying-scp-errors"></a>

| **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** <a href="#id-6-debugging-and-logs" id="id-6-debugging-and-logs"></a>

* **Enable P0 debug**

```plaintext
p0 scp --debug <source> <destination>
```

* Shows API calls, key issuance, and provisioning messages.
* 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:

```plaintext
scp -i /path/to/temp_key <source> <destination>
```

* to isolate SSH vs. provisioning errors.

***

#### **7. Tips & Best Practices** <a href="#id-7-tips-and-best-practices" id="id-7-tips-and-best-practices"></a>

* **Use --reason** for audit trails, especially when using --sudo.
* **Quote paths** with spaces:

```plaintext
p0 scp "prod-web:/var/www/My Site/index.html" ./
```

* **Combine flags correctly**:
  * P0 options before --
  * scp options after --

```plaintext
p0 scp --recursive ./dir prod-app:/opt/app/ -- -C -P 2222
```

* **Confirm valid SSH destinations** before copying:

```plaintext
p0 ls ssh session destination --size 10
```

* Ensures your target hostname exists in P0's session destinations.
* **Automate with debug** when iterating:

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.p0.dev/p0-cli/troubleshooting/p0-scp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
