The basic process: rename your user account or create a new one

You have two paths: rename your existing SSH user account, or create a new account and delete the old one. Renaming is faster if you have few files and permissions to move. Creating a new account is safer if you have a lot of active services running under that username, because you can test everything before switching over.

Both methods require you to be logged in as root or as a user with sudo privileges. If you cannot run sudo commands, you will need root access through another method — usually a console provided by your hosting provider or a direct server connection.

Before you start, log in to your server and write down the exact username you want to change from and the exact username you want to change to. Usernames on Linux must be lowercase letters, numbers, hyphens, and underscores only — no spaces or special characters.

Key Takeaways

  • Renaming your user account with usermod -l takes one command but requires you to also rename the home directory and fix file ownership afterward.
  • Creating a new account and deleting the old one is safer for servers with many running services, because you can test the new account before removing the old one.
  • After any username change, you must update your SSH key location, your cron jobs, and any scripts or services that reference the old username.
  • Always keep a second way to log in (root access or a second admin account) until you confirm the new username works over SSH.
  • File ownership and home directory paths must be updated or your SSH login will fail and your files will be inaccessible.

Method 1: Rename the existing user account

Log in as root or a user with sudo access. Then run this command, replacing oldusername with your current username and newusername with the one you want:

sudo usermod -l newusername oldusername

This renames the user account in the system files. However, it does not rename the home directory. You must do that separately:

sudo mv /home/oldusername /home/newusername

Now update the home directory path in the user account record:

sudo usermod -d /home/newusername newusername

Finally, fix the file ownership so the new username owns all the files in the home directory:

sudo chown -R newusername:newusername /home/newusername

Test the change by logging out and logging back in with the new username. If you cannot log in, log back in as root and check that the home directory path and file ownership are correct.

Method 2: Create a new account and migrate files

This method is safer for production servers because you can test the new account while the old one still works. Create the new user account:

sudo useradd -m -s /bin/bash newusername

The -m flag creates a home directory. The -s /bin/bash flag sets the login shell to bash. If your server uses a different shell, replace /bin/bash with the path to that shell.

Copy the SSH public key from the old account to the new one. Log in as the old user and copy the contents of ~/.ssh/authorized_keys. Then log in as the new user and paste it into a new ~/.ssh/authorized_keys file. Make sure the permissions are correct:

sudo chmod 700 /home/newusername/.ssh sudo chmod 600 /home/newusername/.ssh/authorized_keys

Copy any other files you need from the old home directory to the new one. Then test logging in as the new user over SSH. Once you confirm everything works, delete the old account:

sudo userdel -r oldusername

The -r flag removes the home directory as well. If you want to keep the home directory for backup, omit the -r flag.

Update SSH keys and file paths after the change

If you generated SSH keys specifically for the old username, you may need to update your local SSH configuration. On your local machine, check ~/.ssh/config for any lines that reference the old username and update them to the new one.

If you use key-based authentication with a specific key file, make sure the key file path in your SSH config points to the correct location. For example:

Host myserver   HostName example.com   User newusername   IdentityFile ~/.ssh/myserver_key

Check any cron jobs that run under the old username. List them with sudo crontab -u newusername -l to see what is scheduled. If you migrated cron jobs from the old account, they should now run under the new username.

Search for any scripts, services, or configuration files that hardcode the old username. Common places to check are /etc/sudoers, systemd service files in /etc/systemd/system/, and any process configuration files in the home directory.

Verify the new username works before removing the old account

Open a new terminal window and try to log in as the new user without closing your current session. This way, if something goes wrong, you still have a working connection:

ssh newusername@your-server-address

Once you are logged in, check that you can read and write files in your home directory. Run a few commands to make sure your shell environment is set up correctly. Check that any services or cron jobs that depend on this username are still running.

If you used Method 1 (renaming), you are done — the old username no longer exists. If you used Method 2 (creating a new account), keep the old account active for at least a few days while you monitor the new one. Once you are confident everything is working, delete the old account as described above.

What to do if SSH login fails after the change

If you cannot log in with the new username, the most common causes are incorrect file ownership, wrong home directory path, or missing SSH keys. Log in as root or through your hosting provider's console and check these things in order.

First, verify the home directory path is correct:

sudo grep newusername /etc/passwd

The output should show the home directory path. If it is wrong, fix it with usermod -d as shown above.

Second, check that the new user owns the home directory and all files in it:

sudo ls -la /home/newusername

If the owner is listed as a number instead of the username, or if it shows the old username, run the chown command again.

Third, check that the .ssh directory and authorized_keys file have the correct permissions (700 and 600 respectively). If the permissions are wrong, SSH will refuse to use the keys.

Frequently Asked Questions

Do I need to change my SSH username?

No, but some people do it for security or organizational reasons. A generic username like "admin" or "user" is easier to guess than a unique one. Changing it does not make your server significantly more find if you are already using SSH keys and disabling password login, but it can be part of a broader security plan.

Will changing my username break my website or applications?

Only if your website or process code hardcodes the username in file paths or configuration files. Before you change the username, search your process directory for references to the old username. If you find any, update them to use the new username or use a relative path instead.

Can I change the username of the root account?

No. The root account is special and must always be named "root". If you want a different administrative username, create a new user account and add it to the sudo group instead.

What if I have multiple SSH keys for the old username?

Copy the entire .ssh directory from the old home directory to the new one, then fix the ownership and permissions. All your keys will be available under the new username.

How do I undo a username change?

Use the same process in reverse: rename the new username back to the old one, or create the old account again and migrate files back. If you deleted the old account with the -r flag, the home directory is gone, so you will need to restore it from a backup.