MongoDB

Atlas Auth Commands

“This brief tutorial will explore the commands we can use to connect the Atlas CLI with your MongoDB Atlas deployment.

It is good to perform authentication to your development machines and restrict other addresses outside your network from accessing your cluster.

This ensures that you have sufficient security measures to protect your data.”

Atlas CLI Installation

Before you can use the Atlas commands on your machine, you need to ensure the MongoDB Atlas tools are installed on your machine.

This tutorial will install the Atlas CLI tools on the Debian system. However, you can check the MongoDB documentation for installation instructions on other systems.

Start by updating the system repositories:

$ sudo apt-get update

 
Install GNUPG package.

$ sudo apt-get install gnupg -y

 
Import MongoDB public GPG key with the command:

$ wget -qO - https://pgp.mongodb.com/server-5.0.asc | sudo apt-key add -

 
Create a repository file for MongoDB with the command:

$ echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

 
Refresh the system packages:

$ sudo apt-get update

 
Install MongoDB Atlas and Atlas CLI.

$ sudo apt-get install mongodb-atlas mongodb-atlas-cli

 
Verify the installation has been completed successfully and run the command below to show the current Atlas version.

$ atlas --version

 
The command above should return the output as shown:

atlascli version: 1.1.7
git version: 2ac7d5cf94baa17b50e783a0f8a579695d9d0b4e
Go version: go1.18.2
   os: linux
   arch: amd64
   compiler: gc

 

Atlas Auth Options

To perform authentication to your Atlas account, we use the atlas auth command. The command syntax is as shown:

Usage:
  atlas auth [command

 
The command supports the following flags.

Flags:
  -h, --help   help for auth

Global Flags:
  -P, --profile string   Profile to use from your configuration file.

 

Atlas Auth Subcommands

The atlas auth commands support the following subcommands:

login - authenticate mongodb atlas
whoami - verify and display information about auth state
logout – log out of the atlas CLI
register – register with mongodb atlas

 

Atlas Login

To connect your atlas CLI with your Atlas Account, run the command:

$ atlas auth login

 
The command will generate a verification to connect to your CLI.


To log out, use the command:

$ atlas auth logout

 

To check the currently logged-in user:

$ atlas auth whoami

 
Output:

Logged in as test@email.com

 
To register with the atlas:

$ atlas auth register

 

Conclusion

This post discusses the various commands and subcommands you can use to interact with your MongoDB Atlas cluster from the command line. We discussed topics such as login commands, authentication commands, and more. Feel free to check the docs for more information.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list