๐ค User #
In my php hoster's cpanel i can generate subdomains Have ssh access but only user rights Can i script the generating of subdomains?
๐ ChatGPT #
Yes, but only if your hosting provider allows it via one of the following:
1. Use cPanelโs API (UAPI) #
cPanel provides an API you can call over HTTPS to create subdomains.
API endpoint
1POST /execute/SubDomain/addsubdomain
Example cURL command
1curl -u "cpanel_user:cpanel_password" \
2 -H "Authorization: Basic $(printf '%s' "cpanel_user:cpanel_password" | base64)" \
3 "https://yourdomain.com:2083/execute/SubDomain/addsubdomain?domain=sub&rootdomain=yourdomain.com&dir=public_html/sub"
Requirements
โ cPanel account โ Ability to use HTTPS from your script โ API access not blocked by your host
2. Use SSH + cPanel API tokens (better than password) #
In cPanel, go to:
cPanel โ Security โ API Tokens โ Create Token
Then use:
1curl -H "Authorization: cpanel youruser:YOUR_API_TOKEN" \
2 "https://yourdomain.com:2083/execute/SubDomain/addsubdomain?domain=test&rootdomain=yourdomain.com&dir=public_html/test"
The safest way.
3. What you CANNOT do #
With only user-level SSH access, you cannot:
- Modify Apache/Nginx configs directly
- Create DNS zones manually
- Edit system-wide domain settings Those are root-only tasks. So your only option is cPanelโs API
4. Example Bash script to create subdomains automatically #
1#!/bin/bash
2
3API_TOKEN="YOUR_TOKEN"
4USER="cpaneluser"
5HOST="yourdomain.com"
6
7SUB=$1
8DOMAIN="yourdomain.com"
9DIR="public_html/$SUB"
10
11curl -s -H "Authorization: cpanel $USER:$API_TOKEN" \
12 "https://$HOST:2083/execute/SubDomain/addsubdomain?domain=$SUB&rootdomain=$DOMAIN&dir=$DIR"
Usage:
1./addsub.sh blog
โ Want me to write:
โ a full script? โ a PHP version? โ a bulk-generator to create many subdomains at once?
last updated:
