You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enhance add_http_auth.sh script to support IP-based access control and Apache version compatibility. Update README files to reflect new features and usage instructions.
Copy file name to clipboardExpand all lines: README.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ This repository contains a collection of bash scripts organized by category:
10
10
11
11
Scripts for managing HTTP authentication in web servers.
12
12
13
-
-[add_http_auth.sh](http-auth/add_http_auth.sh) - Add HTTP Basic authentication to an .htaccess file
13
+
-[add_http_auth.sh](http-auth/add_http_auth.sh) - Add HTTP Basic authentication to an .htaccess file with support for IP-based access control and compatibility with both Apache 2.2 and 2.4
2. It then checks if the .htaccess file already exists and if authentication is already configured
114
131
3. If a password is not provided as an argument, it prompts the user to enter one
115
132
4. It creates or updates the .htpasswd file with the username and hashed password
116
-
5. Finally, it adds the necessary authentication directives to the .htaccess file
133
+
5. If IP addresses are specified, it adds rules to allow those IPs to bypass authentication
134
+
6. Finally, it adds the necessary authentication directives to the .htaccess file
117
135
118
136
## Encryption Methods
119
137
@@ -123,13 +141,49 @@ The script supports three encryption methods:
123
141
2.**md5**: Compatible with most servers, requires the `openssl` command
124
142
3.**sha1**: Stronger than md5 but less secure than bcrypt, requires the `openssl` command
125
143
144
+
## IP-Based Access
145
+
146
+
When you specify IP addresses with the `-i` option, the script adds rules to the .htaccess file that allow those IPs to access the protected content without authentication. This is useful for:
147
+
148
+
- Office networks where you want to allow access without prompting for credentials
149
+
- Development or staging environments where you want to restrict access but allow certain IPs
150
+
- Monitoring services that need to access the site without authentication
151
+
152
+
The IP addresses should be provided as a comma-separated list without spaces, for example: `192.168.1.100,10.0.0.5`
153
+
154
+
## Apache Version Compatibility
155
+
156
+
The script supports both Apache 2.2 and Apache 2.4 syntax for access control:
By default, the script uses Apache 2.4 syntax. If you're using an older Apache server (version 2.2), specify `-a 2.2` when running the script.
178
+
126
179
## Security Considerations
127
180
128
181
- When using the `-s` option to specify a password on the command line, be aware that the password may be visible in the process list or command history
129
182
- For production environments, it's recommended to use the interactive password prompt
130
183
- Make sure the .htpasswd file is stored in a location not accessible from the web
131
184
- Ensure proper file permissions are set on both .htaccess and .htpasswd files
132
185
- Use bcrypt encryption when possible for better security
186
+
- Be careful when allowing IP addresses to bypass authentication, as IP addresses can be spoofed
133
187
134
188
## Troubleshooting
135
189
@@ -149,6 +203,14 @@ The script supports three encryption methods:
149
203
- Ensure your web server is configured to allow .htaccess overrides
150
204
- Check that the path to the .htpasswd file in the .htaccess is correct and accessible by the web server
151
205
206
+
5.**IP-based access not working**
207
+
- Make sure your Apache server has the required modules enabled:
208
+
- For Apache 2.2: `mod_setenvif`, `mod_authz_host`
209
+
- For Apache 2.4: `mod_authz_core`, `mod_authz_host`
210
+
- Check that you're using the correct IP address format
211
+
- Verify that your server is properly detecting the client's IP address
212
+
- Ensure you're using the correct Apache version syntax (`-a 2.2` or `-a 2.4`)
213
+
152
214
## License
153
215
154
216
This script is released under the MIT License. See the LICENSE file for details.
0 commit comments