Codementor Events

How to Access an Ubuntu Instance in Oracle Cloud Infrastructure as Root User

Published May 14, 2023

When you launch an Ubuntu instance in Oracle Cloud Infrastructure, it is created with a default user named "ubuntu". By default, this user has sudo privileges, which means you can use the sudo command to perform administrative tasks. However, there may be times when you need to log in as the root user to perform certain tasks. Here's how you can access an Ubuntu instance in Oracle Cloud Infrastructure as the root user.

Step 1: Configuring PermitRootLogin in the SSH Configuration File

To log in as the root user over SSH, you'll need to configure the SSH daemon to allow root login. Here's how you can do this:

  1. Log in to the Ubuntu instance as a user with sudo privileges.
  2. Open the SSH configuration file using a text editor such as nano:
sudo nano /etc/ssh/sshd_config
  1. Find the line that says #PermitRootLogin prohibit-password and uncomment it by removing the '#' character at the beginning of the line.
  2. Change the value to PermitRootLogin yes.
  3. Save and close the file.

6.Restart the SSH service to apply the changes:

sudo systemctl restart ssh

Step 2: Create a New Public Key for the Root User

  1. Log in to the Ubuntu instance as a user with sudo privileges.
  2. Create a new public and private key pair using the ssh-keygen command:
sudo ssh-keygen -t rsa -b 4096 -f /root/.ssh/new_key
  1. When prompted, enter a passphrase for the new key pair (optional).
  2. This will create a new private key file named /root/.ssh/new_key and a corresponding public key file named /root/.ssh/new_key.pub.
  3. Copy the contents of the new public key file using a text editor or the cat
sudo cat /root/.ssh/new_key.pub
  1. Add the contents of the new public key file to the authorized_keys file for the root user:
sudo sh -c 'cat /root/.ssh/new_key.pub >> /root/.ssh/authorized_keys'
  1. Ensure that the file permissions are set correctly:
sudo chmod 600 /root/.ssh/authorized_keys
sudo chmod 700 /root/.ssh

You can now use the new private key file (/root/.ssh/new_key) to log in as the root user over SSH.

Discover and read more posts from JamesPoon
get started
post commentsBe the first to share your opinion
Esha Malik
4 months ago

Unlock root access to your Oracle Cloud Infrastructure Ubuntu instance effortlessly. Navigate to https://gptcodingprompts.com/ for a detailed, step-by-step solution, ensuring efficient resolution and empowering you with comprehensive control over your system.

Puchu Singh
5 months ago

I’m truly grateful for your support and guidance. You’re amazing https://capcutgeek.com/middle-of-the-night-capcut-template/

Ilven Jack
9 months ago

To access an Ubuntu instance in Oracle Cloud Infrastructure as the root user, you can initially connect via SSH using the key pair you provided during instance creation. Once logged in, you can switch to the root user by using the “sudo” command, which provides administrative privileges. However, it’s important to exercise caution while working as the root user, as it grants unrestricted access to system files and configurations, potentially leading to unintended consequences. For enhanced security, consider creating a separate user with sudo privileges for routine tasks and only use the root user when necessary. For instance, just as accessing an Ubuntu instance requires responsible management, you can enhance your gaming experience responsibly by downloading the Little Big Snake mod apk from trustworthy sources such as https://apkrankers.com/little-big-snake-mod-apk/, ensuring a safe and enjoyable gameplay environment.

Show more replies