# SSH and SFTP

> Reveal and rotate your SFTP and SSH credentials, add SSH keys, restrict access by IP, and add extra SFTP accounts with their own folders.

Source: https://docs.wpwaterfall.com/ssh-and-sftp

Every environment has one primary SFTP and SSH user. Open your site, then **Info**, to see the host, port, and username under **Primary SFTP and SSH user**, reveal the password, add keys, and restrict who can connect. Each environment has its own credentials, and the page names the environment they belong to. The SSH port is a number from 22001 to 25999, not 22, so copy it from **Info**.

## Reveal the credentials

1. Open your site, then **Info**.
2. Under **Primary SFTP and SSH user**, choose to show the password.
3. Enter your account password again.

WP Waterfall asks for your account password before it shows a secret, and it hides the secret after a minute. The reveal is session only: it is never stored in your browser. Every reveal is audited and shows on the User activity tab with your name. Copy the password from here, or rotate it.

## Rotate the credentials

Choose to rotate the password when you think it leaked or when someone who had it leaves. WP Waterfall sets a new password through a job. Anything that used the old password stops working until you update it.

## Connect

The connection commands for SSH and SFTP are ready to copy. You can also download the FTP client config file and import it into your client.

An SFTP session and an SSH sign-in start in the site's folder, `/var/www/html`, and `cd ~` takes you to your home folder.

After an SSH sign-in you see the WP Waterfall name, then the site and the environment you are on, such as `my-site (staging)`, so you always know which one a terminal is connected to. A Git push, an SFTP session, and a command run over SSH print nothing extra.

## Add an SSH key

Add your public key to sign in without a password. Remove a key when you no longer use that computer. Each change applies through a job. Adding a key asks for your password if you have not entered it in the last 10 minutes.

Keys added here belong to this one environment. For Git, add your key once to your account instead: it works on every staging and preview environment you may push code to. See [How do I add an SSH key to my account?](https://docs.wpwaterfall.com/git-access#how-do-i-add-an-ssh-key-to-my-account). While a repository is connected to the environment, SFTP and SSH users on **Info** are off. The API refuses new SFTP users, turning SFTP on, and the SFTP credentials with 409 `external_repository_connected`, and a job queued earlier ends before it reaches the server. Disconnect the repository to get SFTP back.

## SSH settings

Edit the authentication methods and the password expiration. Allow keys only to stop password sign-in, or keep both. Set an expiration so passwords must be rotated.

A change that opens SSH up asks for your password if you have not entered it in the last 10 minutes: turning SSH on, turning password sign-in on, and an allowed address list that lets in a new address or is emptied. Turning something off or narrowing the list asks for nothing.

## Restrict by IP

Edit the IP allowlist to limit SSH and SFTP to the addresses you choose, such as your office. When the list is empty, every address can try to connect. The list applies through a job. Five failed logins from one address within ten minutes block that address for an hour. This also stops Git over SSH from that address.

## Extra SFTP accounts

Additional SFTP users each get one folder. Use them to give a contractor access to one theme folder without the rest of the site, or, on live, to let a person download the live files and add media to the uploads folder. Every environment takes them, live included.

1. Open **Info** and find **Additional SFTP users**.
2. Choose **Add new user**.
3. Enter a **Username**: 3 to 32 lowercase letters, digits, hyphens, or underscores.
4. Check the **Password**. WP Waterfall makes one in your browser and shows it. Choose the eye to hide it, the arrows for a new one, and the copy icon to copy it. You can type your own: use 16 to 32 characters, with no spaces or colons.
5. Set the **Root directory**. The web root, `/var/www/html/`, is fixed. Type a subdirectory after it, such as `wp-content/themes/agency`, or leave it empty for the whole site. The user sees only that folder. WP Waterfall makes the folder when it is missing.
6. Pick the **Access**. On staging or a preview in SFTP mode: **Read, write** or **Read only**. On live, and on staging or a preview in Git mode: **Read, and upload to the uploads folder** or **Read only**.
7. Choose **Add new user**. The dashboard asks for your account password first, because a new user comes with a password.

The password you chose is not shown again. Reveal it later the same way as the primary credentials, with your account password. Remove a user you no longer need from its row menu.

### Live and Git mode: read, and upload to the uploads folder

Live code is read only, and so is code in Git mode on staging and previews. Nobody can write a code file there. A user is one of two kinds:

- **Read, and upload to the uploads folder** sees and downloads every file of the site. It can also add files and folders to `wp-content/uploads`, replace them, rename them, and delete them. That is the folder WordPress keeps your media in, and it is content, not code. The user cannot change anything else: not themes, plugins, `mu-plugins`, `wp-config.php`, or the cache folder. It cannot make links either. The dialog starts with this choice.
- **Read only** sees and downloads files and changes nothing.

A user who uploads needs the **Root directory** to be the whole site or `wp-content`, so it can reach the uploads folder. A folder inside `wp-content/uploads` does not work for any user on live: the server cannot confine a user to a folder the web user owns, and the user may be unable to sign in.

Uploaded code does not run. PHP files in the uploads folder, such as `.php`, `.phtml`, and `.phar`, answer 403 and never reach PHP, and `.htaccess` and `.user.ini` files are never served and change nothing. The SFTP server cannot refuse a file by its name, so the web server is what keeps those files inert. PHP also refuses to run any script whose real path is in the uploads or cache folder, even when a link or the web root would lead there, and WP Waterfall refuses a web root of `wp-content` or of a folder inside uploads or cache.

An uploaded page does not run as part of your site either. A file that opens as a page in a browser (HTML, SVG, XML, and the like) is served from uploads with a `Content-Security-Policy: default-src 'none'; sandbox` header, so a script in it cannot read your site or act as a signed-in visitor. Images, video, audio, and PDF files are not affected, and an SVG you use as an image on a page still shows. Opening an uploaded SVG or HTML file on its own shows it without scripts and without its own styles.

When you switch a user off or remove it, or switch SFTP off, every session that user has open ends at once. Removing a user also deletes its password from the server, so a new user with the same name starts with a new password.

Make code changes on staging and [promote them](https://docs.wpwaterfall.com/code/git-workflow#promote-to-live). Switch staging or a preview to SFTP mode to give a user **Read, write**. In SFTP mode that covers your own must-use plugins in `wp-content/mu-plugins` too. The two WP Waterfall entries there, `wpwaterfall.php` and the `wpwaterfall` folder, stay read only for every user (see [Your own must-use plugins](https://docs.wpwaterfall.com/plugins#your-own-must-use-plugins)). See [Git access](https://docs.wpwaterfall.com/git-access#what-are-the-two-modes). A user keeps the access it was made with: one made as **Read, and upload to the uploads folder** only reads while its environment is in SFTP mode, and uploads again when the environment goes back to Git mode. To change a user's access, remove the user and add it again.

Accounts made on live before the upload choice exist stay **Read only**, with the password they had. Nothing changes for them until you remove and add them again.

### What the folder check does

Before the user exists, the server checks the folder. It must be below the web root with no `..`. A link in the site that leads out of the site is refused. A missing folder is made, except where code is read only (live, Git mode): there the job fails and says to make the folder on staging and promote. If the server may refuse the user's sign in because of who owns the folder, the job shows a warning and still succeeds.

The Enable all and Disable all button is gone from the dashboard. Turn SFTP and SSH off for the whole environment with **Disable** on **Primary SFTP and SSH user**. The API route `PUT /v1/environments/{id}/sftp-accounts/status` and the `manage_sftp_accounts` actions `enable_all` and `disable_all` still switch the extra users on or off.

## Quick answers

**I rotated the password and my deploy script broke.**
Update the script with the new password, or switch it to an SSH key.

**Can a Site Developer reveal credentials?**
No. Only a Site Admin can reveal credentials or manage SSH on the site. See [Give someone access to one site](https://docs.wpwaterfall.com/site-users).

## API

- `GET /v1/environments/{id}/credentials/sftp`
- `POST /v1/environments/{id}/credentials/rotate`
- `GET /v1/environments/{id}/ssh`
- `PATCH /v1/environments/{id}/ssh`
- `GET /v1/environments/{id}/ssh/allowed-ips`
- `PUT /v1/environments/{id}/ssh/allowed-ips`
- `GET /v1/environments/{id}/ssh/config` (the `host_key_fingerprint` is null until the server reports it)
- `GET /v1/environments/{id}/local-dev`
- `POST /v1/environments/{id}/ssh-keys`
- `DELETE /v1/environments/{id}/ssh-keys/{key_id}`
- `GET /v1/environments/{id}/sftp-accounts`
- `POST /v1/environments/{id}/sftp-accounts` (`username`, `directory`, and the optional `password` of 16 to 32 characters and `access` of `read_write`, `read_only`, or `read_upload`; `read_upload` needs read only code and a directory of `/` or `/wp-content`, and answers 409 `agent_too_old` until the server has the upload update)
- `PUT /v1/environments/{id}/sftp-accounts/status`
- `DELETE /v1/sftp-accounts/{id}`

## Related

- [Site information](https://docs.wpwaterfall.com/site-info)
- [Git access](https://docs.wpwaterfall.com/git-access)
- [Develop locally with DDEV](https://docs.wpwaterfall.com/develop-locally-with-ddev)
- [Database access](https://docs.wpwaterfall.com/database-access)
- [Files manager](https://docs.wpwaterfall.com/files-manager)
- [See what happened on a site](https://docs.wpwaterfall.com/site-activity)
- [IP deny](https://docs.wpwaterfall.com/ip-deny)
