Add an SSH-Enabled User

If you’ve created your instance using an Oracle-provided Oracle Linux image, then you can use SSH to access your Oracle-provided Oracle Linux instance from a remote host as the opc user. After logging in, you can add users on your instance.

  1. Generate an SSH key pair for the new user. See Generate an SSH Key Pair.
  2. Copy the public key value to a text file. You’ll use this key later in this procedure.
  3. Log in to your instance. See Log In to a VM Using SSH.
  4. Become the root user.
    sudo su
  5. Create the new user:
    useradd new_user
  6. Create a .ssh directory in the new user’s home directory.
    mkdir /home/new_user/.ssh
  7. Copy the SSH public key that you noted earlier to the /home/new_user/.ssh/authorized_keys file.
    echo "key" > /home/new_user/.ssh/authorized_keys
    Here, key is the SSH public key value from the key pair that you generated earlier, enclosed in double quotation marks.
  8. Add the new user to the list of allowed users in the /etc/ssh/sshd_config file on your instance, by editing the AllowUsers parameter, as shown in the following example:
    AllowUsers opc myadmin
    In this example, the AllowUsers parameter already had the opc user. The myadmin user has now been added.
  9. Change the owner and group of the /home/username/.ssh directory to the new user:
    chown -R new_user:group /home/new_user/.ssh
  10. Restart the SSH daemon on your instance.
    /sbin/service sshd restart
  11. To enable sudo privileges for the new user, edit the /etc/sudoers file by running the visudo command.
    In /etc/sudoers, look for the following line:

    %opc ALL=(ALL) NOPASSWD: ALL

    Add the following line right after the preceding line:

    %group_of_new_user ALL=(ALL) NOPASSWD: ALL

You can now log in as the new user:

ssh new_user@ip_address -i private_key

In this command, ip_address is the public IP address of the instance, and private_key is the full path and name of the file that contains the private key corresponding to the public key that you added to the authorized_keys file earlier in this procedure.

If an error occurs, see Can’t connect to an instance using SSH in Using Oracle Cloud Infrastructure Compute Classic.

Use the sudo command to run administrative tasks.