How to register RHEL 8 with subscription manager using command-line

Here is how to register and subscribe a VM or server to the Red Hat Customer Portal using command line.

We use the subscription-manager command that registers systems to a subscription management service and then attaches and manages subscriptions for software products

Step 1. Command to register the system

sudo subscription-manager register --username {RHN-USER} --password {RHN-PASSWORD} --auto-attach

Prompt for the password:

sudo subscription-manager register --username {RHN-USER} --auto-attach
sudo subscription-manager register --auto-attach
[sudo] password for monk: 
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: my_username_here
Password: 
The system has been registered with ID: xyz_abc_123
The registered system name is: rhel8-gold-aws-ec2
Installed Product Current Status:
Product Name: Red Hat Enterprise Linux for x86_64
Status:       Subscribed

Step 2. Removing this VM/Server from RHN (optional)

Unregistering a system is easy too if you no longer need it:

sudo subscription-manager remove --all
sudo subscription-manager unregister
sudo subscription-manager clean

Step 3. Registration via GUI RHEL 8 option

sudo subscription-manager-gui

Step 4. Testing RHEL 8 with subscription manager

We run and see if we can get updates:

sudo dnf update

My system worked:

Updating Subscription Management repositories.
Last metadata expiration check: 0:03:38 ago on Wednesday 10 February 2021 07:32:32 AM EST.
Dependencies resolved.
 Package                                                    Architecture                              Version                                                                       Repository                                                           Size
Installing:
 kernel                                                     x86_64                                    4.18.0-240.10.1.el8_3                                                         rhel-8-for-x86_64-baseos-rpms                                       4.3 M
 kernel-core                                                x86_64                                    4.18.0-240.10.1.el8_3                                                         rhel-8-for-x86_64-baseos-rpms                                        30 M
 kernel-modules                                             x86_64                                    4.18.0-240.10.1.el8_3                                                         rhel-8-for-x86_64-baseos-rpms                                        26 M
Upgrading:
 NetworkManager                                             x86_64                                    1:1.26.0-12.el8_3                                                             rhel-8-for-x86_64-baseos-rpms                                       2.4 M
 NetworkManager-libnm                                       x86_64                                    1:1.26.0-12.el8_3                                                             rhel-8-for-x86_64-baseos-rpms                                       1.8 M
 NetworkManager-team                                        x86_64                                    1:1.26.0-12.el8_3                                                             rhel-8-for-x86_64-baseos-rpms                                       142 k
 NetworkManager-tui                                         x86_64                                    1:1.26.0-12.el8_3                                                             rhel-8-for-x86_64-baseos-rpms                                       320 k
 curl                                                       x86_64                                    7.61.1-14.el8_3.1                                                             rhel-8-for-x86_64-baseos-rpms                                       353 k

Step 5. Reading man page

All options are documented in the following man page:

man subscription-manager 

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki