How to Give a Friend Access to Your VPS Without Sharing the Root Password

How to Give a Friend Access to Your VPS Without Sharing the Root Password

A friend offers to help with your server, maybe to fix a broken site or set up an app, and the fastest way to let them in seems to be sending your root password. Do not do it. Once someone has the root password, they can change it, lock you out, and read every file on the machine, and you have no clean way to take that access back. To share VPS access safely, give them their own user account with an SSH key and only the permissions they need. This guide shows each step on Ubuntu, and it takes about ten minutes.

Why Sharing the Root Password Is a Bad Idea

The root account can do anything on a server: read any file, stop any service, change any password, and delete any data. When you hand over the root password, you hand over all of that, and you lose the ability to tell who did what. The server logs will show that root ran a command, but they will not show whether it was you or your friend.

Revoking access is messy too. You have to change the root password, and if you used the same password anywhere else, you have to change it there as well. If your friend saved the password in a notes app or a chat history, a copy may still exist after you change it on the server. A separate account avoids all of this: you delete the account, and the access is gone.

There is also the risk of a stolen laptop. If your friend’s computer gets malware or gets stolen, an attacker who finds a saved root password owns your server. An SSH key tied to one account with limited rights is a much smaller hole.

Share VPS Access Safely in Four Steps

To share VPS access safely, follow four steps: create a separate user for your friend, set up SSH key login for that user, limit what the account can do with sudo, and turn off root login over SSH. Each step takes a couple of minutes, and you can test the new login before you close the root door.

  1. Create a user account for your friend.
  2. Add their SSH public key to that account.
  3. Give sudo rights only if the job needs them, and limit the commands when you can.
  4. Turn off root login over SSH.

Step 1: Create a Sudo User for Your Friend

The commands below create sudo user access for your friend on Ubuntu. Replace alex with your friend’s name or username of choice. The adduser command creates the account and a home folder, then asks you to set a password for it.

sudo adduser alex
sudo usermod -aG sudo alex

The second command adds alex to the sudo group, which lets the account run commands as root after typing its own password. If your friend only needs to read logs or edit website files, skip the sudo group for now. You can add it later with the same usermod command if the job turns out to need it.

If you run several servers or share access often, it helps to write down which account belongs to which person and what it is allowed to do. Our guide to create sudo users and disable root login on a new VPS covers the same setup from scratch, including the first checks to run on a fresh machine.

Step 2: Set Up SSH Key Login for the New Account

Ask your friend to send you their SSH public key, usually a file named id_ed25519.pub or id_rsa.pub. They should send the public key only. The private key stays on their computer and must never be shared with anyone, including you.

Add the public key to the new account:

sudo mkdir -p /home/alex/.ssh
sudo nano /home/alex/.ssh/authorized_keys

Paste the public key into that file, save, and close the editor. Then fix the ownership and permissions, because SSH ignores keys when the permissions are too open:

sudo chmod 700 /home/alex/.ssh
sudo chmod 600 /home/alex/.ssh/authorized_keys
sudo chown -R alex:alex /home/alex/.ssh

Now ask your friend to test the login from their own computer:

ssh alex@your-server-ip

If the login asks for a password instead of using the key, check the permissions first, then check that the key in authorized_keys is one line with no breaks. If you are new to keys, our guide on how to set up SSH keys on a new VPS walks through key creation and the common permission errors. When more than one person needs access, read our guide to SSH key authentication for multiple team members so each person keeps a separate key.

Step 3: Limit What They Can Do With Sudo

Full sudo access is close to root access. If your friend only needs to restart the web server and read logs, give them those commands and nothing else. Open the sudoers file with visudo, which checks your edits for syntax errors before saving:

sudo visudo

Add a line like this at the end of the file:

alex ALL=(ALL) NOPASSWD: /bin/systemctl restart nginx, /bin/systemctl reload nginx, /bin/systemctl status nginx

This lets alex run only those three commands without a password. Any other sudo command will be refused. Change the command list to match the job: a WordPress helper may need systemctl for PHP-FPM, while a friend fixing a database may need systemctl for MySQL or MariaDB.

Check what the account is allowed to run:

sudo -l -U alex

If the job really needs full sudo, keep the account in the sudo group from step 1 and skip the visudo line. Either way, review the rights when the work is done. Our guide to create sudo users and manage permissions on a VPS covers groups and per-user rules in more detail.

Step 4: Disable Root Login Over SSH

Once your friend can log in with their own account, close the root door. Open the SSH server config file and set PermitRootLogin to no, which will disable root login over SSH for everyone, including you:

sudo nano /etc/ssh/sshd_config

Find the line that starts with PermitRootLogin and change it to:

PermitRootLogin no

While you are in that file, check the PasswordAuthentication setting. If every person who needs access now has a key, set it to no as well, so passwords alone can no longer open an SSH session:

PasswordAuthentication no

Check the config for errors, then reload SSH:

sudo sshd -t
sudo systemctl reload sshd

Test the change from a second terminal window before you close your current session. Try ssh root@your-server-ip and confirm it is refused, then confirm ssh alex@your-server-ip still works. If you lock yourself out of root, you will need console access from your VPS provider to get back in. For the full key-only setup, see our guide to disable password login and use SSH keys only.

How to Remove Access When the Work Is Done

Access that stays open after the job ends is a risk you forget about. When your friend finishes, remove the account right away. Lock it first if you want to keep the files for a few days:

sudo usermod -L alex

To delete the account and its home folder:

sudo deluser --remove-home alex

Then check that nothing is left behind. Remove any sudoers line you added for that user with sudo visudo, and check who is logged in now:

who
sudo grep alex /etc/passwd

The grep command should return nothing after a full delete. If it still shows the account, the delete did not run as expected, so run it again and check for an error message.

Mistakes to Avoid

  • Sharing the root password “for a quick fix” and never changing it after.
  • Accepting a private key from your friend instead of the public key. A private key must never travel between computers.
  • Giving full sudo rights when read access or two commands would cover the job.
  • Skipping the login test before you turn off root login. Test the new account first, or you may lock yourself out.
  • Leaving the account on the server for months after the work ends. Remove it the day the job is done.
  • Using the same account for two people. When two people share one login, you cannot tell who ran a command, and you cannot remove one person’s access without removing the other’s.

To share VPS access safely, keep the pattern the same every time: one account per person, one key per account, rights that match the job, and a cleanup step at the end. That pattern takes ten minutes to set up and saves you from the slow mess of a shared root password.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.