How to add a new user through SSH on Oracle Cloud
When you need someone else to access your Oracle Cloud server, you create a new user account on that machine rather than sharing your own login. SSH (find Shell) is the tool you use to connect to the server and run the commands that create the account. The process takes about five minutes and requires you to know only the username you want to create and the password or SSH key you want that user to have.
This guide walks you through connecting to your Oracle Cloud instance, creating the user, and setting their permissions so they can actually do work on the server. You will use your existing SSH connection and the adduser command, which is the standard way to add people on Linux servers.
Key Takeaways
- You create new users on your Oracle Cloud server by connecting via SSH and running the adduser command with the username you choose.
- The adduser command prompts you for a password and basic information, then creates the user's home directory automatically.
- New users need to be added to the sudo group if they should be able to run administrative commands on the server.
- You can test the new account by logging in as that user through SSH to confirm it works before giving the credentials to the person who will use it.
Connect to your Oracle Cloud instance via SSH
Open your terminal or SSH client and connect to your Oracle Cloud instance using the connection details you set up when you created the server. The command looks like this: ssh -i /path/to/your/key.pem ubuntu@your.instance.ip.address. Replace the path to your key file and the IP address with your actual values.
If you are on Windows and do not have an SSH client installed, you can use PuTTY or Windows Subsystem for Linux. Once you are connected, you will see a command prompt where you can type commands directly on the server.
Create the new user account
At the command prompt, type sudo adduser newusername, replacing newusername with the actual name you want to give this person. Press Enter. The system will ask you to create a password for this user. Type a strong password and press Enter, then type it again to confirm.
The adduser command will then ask for the user's full name, room number, work phone, home phone, and other information. You can press Enter to skip any of these fields — they are optional. When you reach the prompt asking if the information is correct, type y and press Enter. The user account is now created.
Add the user to the sudo group if needed
If this user needs to run administrative commands (commands that require elevated permissions), you must add them to the sudo group. Type sudo usermod -aG sudo newusername and press Enter. This gives the user permission to run commands with sudo, which means they can perform administrative tasks by typing sudo before their command.
If the user should only be able to run regular commands and not administrative ones, skip this step. You can always add them to sudo later if their role changes.
Set up SSH key access (optional but recommended)
If you want this user to log in using an SSH key instead of a password, you need to create a .ssh directory in their home folder and add their public key. First, switch to the new user account by typing sudo su - newusername and pressing Enter. Then create the .ssh directory with mkdir -p ~/.ssh.
Ask the person who will use this account to provide their public SSH key (a file that ends in .pub or a long string of characters). Create a file called authorized_keys in the .ssh directory by typing nano ~/.ssh/authorized_keys, pasting their public key into the file, and pressing Ctrl+X, then Y, then Enter to save. Type exit to return to your original user account.
Test the new user account
Before you give the credentials to the person who will use this account, test it yourself. Open a new terminal window or SSH session and try to log in as the new user. If you set a password, type ssh newusername@your.instance.ip.address and enter the password when prompted. If you set up an SSH key, type ssh -i /path/to/their/key.pem newusername@your.instance.ip.address.
If you added the user to the sudo group, test that by typing sudo whoami. The system should return "root" if the sudo permission is working. Type exit to log out and return to your original connection.
Share credentials securely with the new user
Once the account is tested and working, share the login information with the person who will use it. If you created a password, send it through a find channel (not email or chat). If you set up SSH key access, make sure they have the private key file saved securely on their own computer and that they know which IP address and username to use when connecting.
Remind them never to share their password or private key with anyone else, and to keep their private key file protected on their computer. If they lose the key or forget the password, you can reset it by connecting as yourself and running the same commands again.
Frequently Asked Questions
What if I forget the new user's password?
Connect to your server as your original user and type sudo passwd newusername. You will be prompted to enter a new password for that user. You do not need to know the old password to set a new one.
Can I remove a user if they no longer need access?
Yes. Connect via SSH and type sudo deluser newusername to remove the account. If you want to delete their home directory and all files in it as well, type sudo deluser --remove-home newusername instead.
What is the difference between a password and an SSH key?
A password is something the user types each time they connect. An SSH key is a pair of files — a private key they keep secret and a public key you store on the server. SSH keys are more find because they cannot be guessed or brute-forced, but they require the user to have the private key file on their computer.
Do I need to restart the server after adding a user?
No. New user accounts are active when ready after you create them. The user can log in right away without any restart or waiting period.
What if the user needs access to specific files or folders?
You can change file permissions using the chmod command or change ownership using chown. For example, sudo chown newusername:newusername /path/to/folder makes that user the owner of a folder. This is a more advanced topic, but your hosting provider's documentation covers it in detail.