This article provides a guide demonstrating how to copy a cPanel account with SSH keys. This guide is intended for users of cPanel VPS or cPanel dedicated servers.
Migrating a cPanel account to a new server is a common task for web hosting providers, system administrators, and developers. While cPanel's Transfer Tool can migrate nearly everything automatically, there are situations where you may need to manually copy an account while preserving SSH access. Examples include migrating between providers, moving a single account without WHM root access, or cloning an account for development purposes.
This guide demonstrates how to safely copy a cPanel account—including the user's SSH keys—to another cPanel server while maintaining correct ownership and permissions.
Prerequisites
Before beginning, ensure the following:
- Root SSH access to both source and destination servers
- Both servers are running cPanel & WHM
- The destination server has sufficient disk space
- SSH connectivity between servers
- The same cPanel username exists (or will exist) on the destination server
- DNS changes are planned after migration
How to Copy a cPanel Account with SSH Keys
-
Verify the Existing Account
On the source server:
whmapi1 accountsummary user=usernameor
grep "^USERNAME=" /var/cpanel/users/usernameVerify:
- Username
- Domain
- Package
- Home directory
Typically:
/home/username -
Enable SSH Access (If Necessary)
If the user already has SSH enabled, verify:
grep username /etc/passwdCheck the shell:
/bin/bashor
/usr/local/cpanel/bin/noshellTo enable SSH:
WHM
Manage Shell Access
or
whmapi1 modifyacct user=username shell=/bin/bash -
Verify the SSH Keys
SSH keys reside in:
/home/username/.ssh/List them:
ls -la /home/username/.sshTypical output:
authorized_keys id_rsa id_rsa.pub known_hosts configVerify permissions:
stat /home/username/.ssh -
Create a Full cPanel Backup (Recommended)
Although this guide covers manual migration, always create a backup first.
/scripts/pkgacct usernameResult:
/home/cpmove-username.tar.gz -
Copy the Account
If using rsync:
rsync -avz \ /home/username \ root@destination:/home/Or with SCP:
scp -r /home/username \ root@destination:/home/ -
Copy SSH Keys Separately (Recommended)
Although they are inside the home directory, verify separately.
Using rsync:
rsync -avz \ /home/username/.ssh \ root@destination:/home/username/ -
Restore Ownership
On the destination server:
chown -R username:username /home/usernameVerify:
ls -ld /home/usernameExample:
drwx--x--- username username -
Restore SSH Permissions
SSH is extremely strict about permissions.
Set:
chmod 700 /home/username/.sshchmod 600 /home/username/.ssh/authorized_keyschmod 600 /home/username/.ssh/id_rsachmod 644 /home/username/.ssh/id_rsa.pubchmod 644 /home/username/.ssh/known_hosts -
Restore SELinux Contexts (If Applicable)
If SELinux is enabled:
restorecon -Rv /home/username/.sshor
restorecon -Rv /home/username -
Verify SSH Configuration
Confirm OpenSSH allows public key authentication.
Check:
/etc/ssh/sshd_configVerify:
PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys PasswordAuthentication yesRestart SSH if modified:
systemctl restart sshd -
Verify Authorized Keys
Inspect:
cat /home/username/.ssh/authorized_keysExample:
ssh-ed25519 AAAAC3Nza...or
ssh-rsa AAAAB3Nza... -
Test SSH Login
From your workstation:
ssh username@example.comOr explicitly specify a key:
ssh \ -i ~/.ssh/id_ed25519 \ username@example.comIf successful:
Last login: -
Verify cPanel's SSH Key Management
Log into cPanel.
Navigate:
Security SSH AccessConfirm:
- Authorized Keys
- Private Keys
- Imported Keys
appear correctly.
If keys are missing in the interface, use:
Manage SSH Keysto import them.
Note: cPanel's SSH Access interface primarily manages key pairs stored under the user's home directory. Simply copying the
.sshdirectory preserves authentication, but imported private keys may not appear in the interface unless they follow cPanel's expected naming and metadata. -
Verify Git Repositories
If the account uses Git:
find /home/username -name ".git"Test cloning:
git pullor
git fetch -
Verify Deployment Keys
Many users rely on SSH keys for:
- GitHub
- GitLab
- Bitbucket
- Private package repositories
- Backup servers
- Remote rsync targets
Test each connection:
ssh -T git@github.comExample:
Hi username! You've successfully authenticated. -
Verify Cron Jobs
Some cron jobs use SSH.
Inspect:
crontab -u username -lLook for:
sshscprsyncRun manually.
-
Verify File Ownership
Run:
find /home/username \ ! -user usernameNo files should be returned.
-
Verify SSH Agent Usage
Some applications depend on an SSH agent.
Check:
env | grep SSHIf using systemd services, ensure:
IdentityFilepaths remain valid.
Common Problems
Permission denied (publickey)
Usually caused by:
- Incorrect permissions
- Wrong ownership
- Wrong authorized_keys
- Incorrect home directory permissions
Verify:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Bad owner or permissions
Run:
chown -R username:username ~/.ssh
SSH key ignored
Check:
tail -f /var/log/secure
or
journalctl -u sshd
Wrong shell
Verify:
grep username /etc/passwd
Expected:
/bin/bash
Home directory permissions
OpenSSH rejects insecure home directories.
Typical:
chmod 711 /home/username
or
chmod 750 /home/username
depending on your hosting policy.
Best Practices
- Prefer Ed25519 keys over RSA for new deployments.
- Always use
rsync -ato preserve permissions, ownership, timestamps, symlinks, and extended attributes when migrating home directories. - Perform migrations over a trusted network or through encrypted SSH tunnels.
- Test SSH authentication before updating DNS or decommissioning the source server.
- Keep a full
pkgacctbackup until the migration has been validated. - Rotate SSH keys if there is any concern they may have been exposed during the migration process.
- If using WHM's Transfer Tool or restoring a
cpmovebackup withrestorepkg, SSH keys stored in the user's home directory are generally preserved automatically. A manual copy of the.sshdirectory is most useful for selective migrations or when you are not using cPanel's built-in migration tools.
Summary
You now know how to copy a cPanel account with SSH keys.
Migrating a cPanel account with SSH keys is largely a matter of preserving the user's home directory correctly and ensuring ownership and permissions are restored exactly as expected. By copying the .ssh directory, validating authorized_keys, restoring proper file permissions, and testing authentication before cutover, you can provide a seamless migration with minimal downtime and no interruption to Git deployments, automation scripts, or other SSH-based workflows.

👀 Choose SSD-powered VPS servers for increased speed, power, and security! Now 50% off- starting from only $3.19/mo.