Add an SSH User

You can add an operating system (OS) user to an Oracle Java Cloud Service node, and then use a secure shell (SSH) utility to connect to the node as the new user.

Before you add a new SSH user to a node, connect to the node as the opc user.

Note:

Use caution when making modifications to a node’s OS configuration as the root user. Certain changes might cause other Java Cloud Service management operations to fail.

  1. Switch to the root user.
    sudo su –
  2. Create a new user.

    useradd username

    For example: useradd myadminuser

  3. Create a directory named .ssh in the new user’s home directory.

    mkdir /home/username/.ssh

    For example: mkdir /home/myadminuser/.ssh

  4. Copy the authorized_keys file from the opc user’s .ssh directory to the new user’s .ssh directory.

    cp /home/opc/.ssh/authorized_keys /home/username/.ssh

    For example: cp /home/opc/.ssh/authorized_keys /home/myadminuser/.ssh

    Note:

    Alternatively, you can create a new SSH key pair for the new user, and paste the contents of the public key into the user’s authorized_keys file. Do not add extra lines or line breaks.
  5. Change the owner of the /home/username/.ssh directory.

    chown —R username:username /home/username/.ssh

    For example: chown —R myadminuser:myadminuser /home/myadminuser/.ssh

  6. Edit the file /etc/ssh/sshd_config. Add the new user to the list of users in the AllowUsers parameter. Separate each user in the list with a space.

    AllowUsers existing_users username

    For example: AllowUsers opc myadminuser

    Important:

    The AllowUsers parameter must be placed before any Match parameters in the sshd_config file.
  7. Verify that there are no errors in your SSH configuration.

    /usr/sbin/sshd –t

    Caution:

    Correct any errors described in the output. Otherwise, the SSH service will not start properly and you will not be able to reconnect to this node.

  8. Restart the SSH service.
    /sbin/service sshd restart
  9. Optional: Run visudo and grant sudo privileges to the new user.

    username ALL=(ALL) NOPASSWD: ALL

    For example: myadminuser ALL=(ALL) NOPASSWD: ALL

  10. Disconnect from the node.
  11. Connect to the node as the new user.
    For example: ssh -i /home/myuser/id_rsa myadminuser@203.0.113.13
  12. If prompted, enter the passphrase for the private key.