Apache Cassandra

Cassandra Alter Users

This article will teach you how to alter an existing role to modify the various properties such as passwords and privileges.

Let us dive in!

The following snippet shows the syntax of the create role in Cassandra:

CREATE ROLE [IF NOT EXISTS] role_name
[WITH SUPERUSER = true | false
 | LOGIN = true | false  
 | PASSWORD =  'password'
 | OPTIONS = option_map]

 
The following are the parameters in the given syntax:

    1. Role_name – This specifies the name that is used to identify a given role. Keep in mind that Cassandra will not letter case unless the name is enclosed in quotation marks.
    2. SUPERUSER – Setting the SUPERUSER value to true automatically grants AUTHORIZE, GRANT, and DROP on all roles. This allows the superusers to manage the other roles in the database.
    3. LOGIN – If set to true, the created role is treated as a standard account, allowing that username to log in with a username and password. By default, this value is set to false.
    4. PASSWORD – It specifies the password that the role will use to log in. Pair this value with LOGIN = true. Otherwise, skip.
    5. OPTIONS – Specifies the options for configured authentication plugins.

Create a User Account

The following example shows how to create a login user using the CREATE ROLE command:

cqlsh> CREATE ROLE linuxhint
   ... WITH PASSWORD = 'password'
   ... AND LOGIN = true;

 
Setting the PASSWORD and LOGIN = true allows you to create a standard user. You can then login into the server with the created user as:

LOGIN linuxhint

 
The command prompts you to enter a password for the specified username. Once authenticated, the prompt should reflect the logged-in user as follows:

linuxhint@cqlsh>

 

Cassandra Alter User Command

The following snippet illustrates the syntax of the Cassandra ALTER USER command:

ALTER USER username
WITH PASSWORD 'password'
[SUPERUSER | NOSUPERUSER]

 
For example, to change the password of the Linuxhint user that was created in the previous example, we can run the following command:

cassandra@cqlsh> ALTER USER linuxhint WITH PASSWORD 'newpassword';

 
The command then modifies the account and set the new password.

To allow the user to contain the superuser privileges, we can run the following command:

cassandra@cqlsh> ALTER USER linuxhint SUPERUSER;

 

Conclusion

In this article, you learned how to use the CREATE ROLE command to create a login user. You also discovered how to alter the various properties of an existing user such as setting a new password and assigning the superuser privileges.

Happy coding!

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