How Nexcess clients can use FTP and SSH to restrict access to web pages to one or more users.
ATTENTION: Any input in brackets ([username], [dev.example.com], and so on) represents a placeholder. Replace the brackets and everything between them with the indicated information.
- Log in using FTP and download your .htaccess file from the folder you wish to protect; for example:
/home/username/dev.example.com/html/.htaccess. If this file is not here, you may need to create it.
- At the top of the .htaccess file, insert the following:
ATTENTION: The AuthUserFile path should be the target location for storing your username and password. We recommend doing this in a location outside of the html folder.
AuthType Basic AuthName "Password Protection" AuthUserFile /chroot/home/[username]/[dev.example.com]/.htpasswd Require valid-user
- If you wish to block a specific page, you would use <FilesMatch>to limit this to a single page, like so:
AuthType Basic AuthName "Password Protection" AuthBasicProvider file AuthUserFile /chroot/home/[username]/[dev.example.com]/.htpasswd <FilesMatch “[secret.php]”> Require valid-user </FilesMatch>
- Log in with SSH, then use the cd command to change your directory to the target directory for the .htpasswd file:
- To generate a new .htpasswd file with one user, issue:
htpasswd -nb [username] [password] > .htpasswdAfter this, you can use htpasswd -nbcommand to generate new username and password combinations to add to the .htpasswd file. For example:
htpasswd -nb [username2] [password2]
- The output will resemble the following; copy it to your clipboard:
- Using FTP, add the new user as a new line to the existing .htpasswd file. Repeat Steps 5 and 6 for every user as necessary. For example: