Note: Root SSH access to the server is required in order to run any of the following commands.
There are quite a few occasions where you might need to generate a one-time login URL (AKA a login session) to any of the cPanel-related interfaces (WHM/cPanel/Webmail). You might have lost your password and need to log into the interface to reset the password. There are times where you might need to provide a developer login access, but you want the access to be only an one-time access. And many other situations where having the capability to generate a temporary user session would come in handy. This capability is built into your cPanel installation and can be achieved in quite a few different ways. Here we will discuss the most convenient ways to achieve such a task.
The WHM Interface:
There are two ways to create a temporary user session to the WHM interface. For the first one, you need to log into the server via SSH as the root user and run the following command:
This script will generate a temporary login URL to the WHM interface. The output looks like this:
firstname.lastname@example.org: ~ /scripts/whmlogin
You need to copy and paste the above URL into the browser's search bar and then you will be able to log into the WHM interface directly without having to enter any login credentials.
Alternatively, you can use the
create_user_session API function call to achieve the same:
whmapi1 create_user_session user=root service=whostmgrd
reason: Created session
Here you can use the URL outputted (highlighted) when the above command is executed.
The cPanel Interface:
Similarly, for the cPanel and the Webmail interfaces, we can use the above API call to generate the temporary URL: (Here you need to replace the cPanel user
cptest with the user for whom you wish to create the temporary URL)
whmapi1 create_user_session user=cptest service=cpaneld
The Webmail Interface:
(You need to replace the email account
email@example.com with the account for which you wish to create the temporary URL):
whmapi1 create_user_session firstname.lastname@example.org service=webmaild