How do I secure a directory with a username and password / วิธีการป้องกันไดเรคทอรีด้วยบัญชีผู้ใช้และรหัสผ่าน
Alternative solutions:
- Server-wide user and group management for password protected directories
Via the control panel
Protecting a directory with a username and password is easy via the Control Panel (my.codeorange.co.th)
Note: this only works for folders under the /example.com/www/ folder. For example /example.com/www/ secrets/
After logging in, you choose the domain for which you want to set this up. Then choose “Secure Folders".
![]()
Click on “New”
![]()
From the drop down, select the folder you want to protect.
![]()
Then enter all the users and passwords and click on “Submit".
![]()
You can remove protection at any time by clicking on "Remove"
![]()
After submitting, it takes 1 minute before the directory protection is in effect. To make sure it works well, check the directory in your browser after a few minutes, to see if you get a pop-up login screen.
Advanced use
A few users
If there are just a few users, you only need 2 files.
.htaccess (indicates to the Apache webserver, what you want to protect)
Note: AuthUserFile should be the full server path to where you stored the .htpasswd file.
AuthType Basic AuthName "Authorized personnel only." AuthUserFile /home/user1234/example.com/www/.htpasswd Require valid-user
.htpasswd (contains all users and passwords)
You can generate these via an online tool such as this one: http://aspirine.org/htpasswd_en.html [this is not an endorsement, do your own research]
Then you save the .htpasswd file and upload it via SFTP or the file manager to the same directory as the .htaccess file.
Note: do save your passwords too, because the .htpasswd file only contains users and hashes of the password. This means you cannot find out what passwords were used. This is secure.
Martha:$apr1$KeMxNI7T$B3XlJOwHRDSJgRxfKtvEk/ Simone:$apr1$/5n96u/Z$JIw7J4CTs4bQersnfh3tO1
Many users? Use groups
Note: AuthUserFile should be the full server path to where you stored the .htpasswd file. Same goes for AuthGroupFile for the .htgroup file
AuthType Basic AuthName "Authorized personnel only." AuthUserFile /home/user1234/example.com/www/.htpasswd AuthGroupFile /home/user1234/example.com/www/.htgroup Require group my1stgroup my2ndgroup
.htpasswd (contains all users and passwords)
You can generate these via an online tool such as this one: http://aspirine.org/htpasswd_en.html [this is not an endorsement, do your own research]
Then you save the .htpasswd file and upload it via SFTP or the file manager to the same directory as the .htaccess file.
Note: do save your passwords too, because the .htpasswd file only contains users and hashes of the password. This means you cannot find out what passwords were used. This is secure.
Martha:$apr1$KeMxNI7T$B3XlJOwHRDSJgRxfKtvEk/ Simone:$apr1$/5n96u/Z$JIw7J4CTs4bQersnfh3tO1 Gabrielle:$apr1$rQMscSmi$/tb7n4/HZ9Mb8yFUxpngh0 Theo:$apr1$sg6m8Qni$HcAYKFotkQsCKhMCCmEya0
.htgroup (has users per group)
Every group is on its own line. Then a colon and then the users separated by spaces.
Upload your .htgroup file via SFTP or the file manager to the same directory as the .htaccess file.
my1stgroup:Martha Simone Gabrielle my2ndgroup:Martha Theo
| . |
การป้องกันไดเรคทอรีด้วยบัญชีผู้ใช้และรหัสผ่านสามารถทำได้โดยการเข้าสู่ระบบด้วยบัญชีผู้ใช้และรหัสผ่านของท่านไปยังหน้า Control Panel ที่ ( my.codeorange.co.th) เลือกโดเมนที่ท่านต้องการตั้งค่า หลังจากนั้นเลือกที่ “Secure Folders"สำหรับภาษาไทยดังนี้
ขั้นตอนแรก สร้างบัญชีผู้ใช้และรหัสผ่านใหม่อย่างน้อยหนึ่งบัญชีผู้ใช้ โดยคลิกเลือกที่ “New”
![]()
ใส่ชื่อบัญชีผู้ใช้ที่ต้องการ ยกตัวอย่างเช่น Administrators แล้วคลิกเลือกที่ “Submit” เพื่อยืนยัน
หากท่านต้องการสร้างบัญชีผู้ใช้มากกว่าหนึ่งบัญชีผู้ใช้ สามารถสร้างเพิ่มได้โดยการคลิกที่ “New User” เลือกกลุ่มไดเรคทอรี่ที่ต้องการใส่ระบบป้องกัน แล้วทำการใส่บัญชีผู้ใช้และรหัสผ่าน หลังจากนั้นคลิกที่ “Create” หากไม่ต้องการป้องกันไดเรคทอรี่นั้นแล้ว ท่านสามารถลบบัญชีผู้ใช้ได้โดยการคลิก “Remove”
ท่านสามารถป้องกันโฟลเดอร์ของท่านโดยการคลิกที่ “Back” เพื่อกลับไปยังหน้าหลักเลือก “Secure Folders” แล้วทำการเลือกที่ “Protect a folder” และเลือกที่ไดเรคทอรีที่ท่านต้องการเปิดการป้องกัน หากท่านเลือก “/“ ท่านต้องป้อนรหัสผ่านในโดเมนทั้งหมด
| เมื่อท่านตั้งค่าเรียบร้อยแล้วระบบจะใช้เวลาสักครู่ในการตั้งค่าการป้องกัน หลังจากนั้นประมาณ 10 นาทีเมื่อท่านไปยังโฟลเดอร์ที่ท่านตั้งค่าไว้จะแสดงหน้าต่างเพื่อให้ท่านกรอกบัญชีผู้ใช้และรหัสผ่าน |