Before You Begin
Purpose
This tutorial shows you how to create an
SSH-enabled user with the System
Administrator profile on a Compute Classic Solaris instance.
Time to Complete
20 minutes
Background
When you create a Compute Classic
instance using an Oracle-provided Solaris image, a
user named opc is created
automatically. Use ssh to log in to
your instance as the opc user, with
the SSH private key that corresponds to the SSH
public key that you specified while creating the
instance. After you've logged in to your instance as
the opc user, create additional
SSH-enabled users on your Compute Classic instance.
Note: When a Compute Classic instance that is set up to boot from a nonpersistent boot disk is stopped and re-created, any OS-level changes you may have made before the instance was stopped, including user creation, are lost. Therefore, use a bootable storage volume to make your changes persistent.
What Do You Need?
-
You've already created a Compute Classic Solaris instance.
-
You know the public IP address of the Compute Classic Solaris instance on which you want to create new users.
-
You have your SSH private key to log in to the Compute Classic Solaris instance.
-
You have
rootpassword for the Compute Classic Solaris instance. See Accessing an Oracle Solaris Instance Using SSH in Using Oracle Cloud Infrastructure Compute Classic.
Generating an SSH Key Pair for the New User
Generate the SSH key pair for the new user. See Generating an SSH Key Pair in Using Oracle Cloud Infrastructure Compute Classic.
Make a note of the following:
- The file name and the path at which the SSH key pair is saved.
- The passphrase for the SSH key if it was set while generating the key pair.
Adding a New User on the Instance
Log in as the opc user
-
Log in to the Compute Classic Solaris instance as the
opcuser with the following command:$ ssh opc@ip_address -i ssh_private_key-
ip_addressis the public IP address of your Compute Classic Solaris instance. -
ssh_private_keyis the complete path and file name of your SSH private key.
-
-
Enter the passphrase for your SSH key if it was set while generating the key pair.
You are now logged in as the
opcuser.opc@xyz:~$
Switch to the root role
Run the following command and enter the root
password when prompted:
opc@xyz:~$ su –
The root prompt appears.
root@xyz:~#
Create the New User
- Create the new user with the
System Administratorprofile and therootrole using the following command:root@xyz:~# useradd -m -P "System Administrator" -R root userExample:
root@c74eb2:~# useradd -m -P "System Administrator" -R root jane
- Check whether a dataset has been created for
the new user.
root@xyz:~# zfs list -r rpool/export/homeThe output includes the home directory of the new user, as shown in the following example:
NAME USED AVAIL REFER MOUNTPOINT rpool/export/home 106K 25.7G 33K /export/home
rpool/export/home/jane 38K 25.7G 38K /export/home/jane
rpool/export/home/opc 35.5K 25.7G 35.5K /export/home/opc
Set the Password for the New User
-
Set the password for the new user using the following command:
root@xyz:~# passwd userExample:
root@ c74eb2:~# passwd jane
-
Enter the new password and re-enter it to confirm.
The password is successfully set for the new user.
-
Check whether the new user has been created with the specified role and profile, by running the following command:
root@xyz:~# cat /etc/user_attrThe following is a sample of the output of this command:
#
# Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
#
# The system provided entries are stored in different files # under "/etc/user_attr.d". They should not be copied to this file. #
# Only local changes should be stored in this file.
#
root::::type=role
opc::::lock_after_retries=no;profiles=System Administrator;roles=root;clearance=ADMIN_HIGH;min_label=ADMIN_LOW
jane::::profiles=System Administrator;roles=rootIn the output, note that the user
janehas been provisioned theSystem Administratorprofile and therootrole.
Logging in As the New User
-
Log out of
rootrole.root@xyz:~# logout
-
Log in as the new user.
opc@xyz:~$ su – userExample:
opc@c74eb2:~$ su – jane
-
Enter the password you created for the new user.
-
Verify that the new user can take on the
rootrole. Run the following command:user@xyz:~$ su -
-
Enter the
rootpassword.The root prompt appears:
root@xyz:~#
Enabling SSH Access for the New User
-
Log out of
rootrole. You're now logged in as the new user.
-
Create a
.sshdirectory.user@xyz:~$ mkdir .ssh
-
Go to the .ssh directory and create the
authorized_keysfile:user@xyz:~$ cd .ssh/
user@xyz:~/.ssh$ vi authorized_keysThe file
authorized_keysopens in vi editor. Copy the content of the public SSH key file created earlier (Example:jane_ssh_rsa.pub) and paste it in theauthorized_keysfile. Save the file and exit the vi editor.The following is a sample of the file
authorized_keysafter pasting the content of the public SSH key file:ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAkDn2ZexgOwqQhEu+jwIOYW0wmvOhV264pP4lFOj5YctJkFNx2imFhuomuSvcHZnihtAzE+wlF6B3ub383eAgaD3GfU0PrPtOiGmMn+4STjddA+3zx/X9u6gO0QlMsq1S8wmrMbVA5e6iofGEqt1sNRe6j4e+CCVM6N1YrEz/VD/4wJOEwsZuMDrkMZhECNbVqZILGHySXUx7dv1iObE0NP2aSUY0OmHOS8su9Kxp0kcXMWtX1+qjfYhb2+lmtVBZfYmiEPSaf/BOMDF1I9MHOIgsFo7GTE824CV25BCsxw3bHtpiIyv0micqztksDAUIiHYPXKKyfMCvuGjg1cqSrQ== rsa-key-20160704
-
Log out of the instance.
Verifying SSH Access as the New User
-
Log in to the Compute Classic Solaris instance with the SSH private key of the new user using the following command:
ssh user@ip_address -i ssh_private_key-
useris the new user added on the instance (Example:jane). -
ip_addressis the public IP address of the Solaris instance. -
ssh_private_keyis the complete path and file name of the SSH private key.
Example:
ssh jane@129.144.29.99 -i /home/.ssh/jane_ssh_rsa -
-
Enter the passphrase for the SSH key of the new user.
user@xyz:~$
Want to Learn More?
-
Reserving a Public IP Address in Using Oracle Cloud Infrastructure Compute Classic
-
Attaching an IP Reservation to an Instance in Using Oracle Cloud Infrastructure Compute Classic
-
Creating a Bootable Storage Volume in Using Oracle Cloud Infrastructure Compute Classic
Credits
-
Lead Curriculum Developer: Mamatha Srinath.
-
Other Contributors: Glynn Foster, Kumar Dhanagopal, Anamika Mukherjee.