π€ 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: