• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Set group password,its use and check which group after newgrp command in linux

July 30, 2013 by Sharad Chhetri Leave a Comment

Set group password,its use and check which group after newgrp command in linux

As per the title of my post it has 3 questions:

(1) How to set group password in Linux ?
(2) What is its use ?
(3) How to know you are using which group after using command newgrp ?

How to set group password in Linux

Follow the given below steps to set group password

Step 1: Either you can create a new group or use the existence group.
To create new group use below command.


groupadd group_name

for eg.

groupadd hr

Step 2: To set group password use below given command

gpasswd group_name

For eg.

gpasswd hr

How to use group passwd

To use the permission and privileges of group you can temporarily join the group by using its group password
User can temporarily join the group which has password already set by below given command

newgrp group_name

for eg.


newgrp hr

In below given example we will see, the user called john do not have read,write,execute permission in directory called /opt/testdir.
The ls -ld command shows it has ownership of joe and group is hr and permission is 770 means only owner joe and group hr have read write execute permission.
But user john can also “read write execute” only when it uses the newgrp command and give group password of hr group.
See the below given scenario, how the john will create a testfile after using newgrp command which he was earlier not able to do so

root@tuxworld:~# ls -ld /opt/testdir/
drwxrwx--- 2 joe hr 4096 Jul 31 01:12 /opt/testdir/
root@tuxworld:~# 
root@tuxworld:~# su -l john
$ whoami
john
$ 
$ touch /opt/testdir/testfile
touch: cannot touch `/opt/testdir/testfile': Permission denied
$ 
$ newgrp hr
Password: 
$ 
$ touch /opt/testdir/testfile
$ ls -l /opt/testdir/testfile
-rw-rw-r-- 1 john hr 0 Jul 31 02:00 /opt/testdir/testfile
$ 
$ exit
$ exit
root@tuxworld:~# 

Note: You can use this in other scenario above one was just an example

How to know you are using which group after using command newgrp

$ groups
john
$ newgrp hr
Password: 
$ groups
hr john
$ id
uid=1011(john) gid=1012(hr) groups=1011(john),1012(hr)
$ groups
hr john
$ whoami
john
$ 
$ id john
uid=1011(john) gid=1011(john) groups=1011(john)
$ 
$ groups
hr john
$ exit
$ exit

To describe about this query I will first start with example.

(A)In below command user name is john and I use the command whoami. By which I got to know the username which I login is john

(B)After this I use the command id john which shows the user john’s UID and GId by which I can also know which is its primary or supplementary GROUPS.(i.e john ,john [here group is also john])

(C)Then I use the command called groups now here you can see the output in which it shows hr group which was not earlier listed with id command.

(D) Hence to know which group you are using after newgrp command ,check with below given two commands
1: id username
2: groups

(E)Now in next step you can see in example, I typed two times exit command .
The first exit command is when it exit out from group called hr
And the Second exit command is when I am doing exit from shell of user john

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. Linux: Set user password by using encrypted password in command
  2. Linux : clear command and its keyboard shortcut
  3. 6 df Command Examples To Check Mounted Filesystem On Linux
  4. Command to create and delete group in Red Hat and CentOS linux
  5. How to increase Password Expire date without resetting the password
  6. Saving every command and its output in log in Unix
  7. Learn tar command and know about its precaution
  8. curl command to check the http status
  9. 4 different commands to check the load average in linux
  10. Allow only members of Wheel group to use su command on RHEL/CentOS

Filed Under: Linux Tagged With: group password

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

4 Different commands to find system uptime in linux

Allow wget and yum in iptable

Print double hyphen sign simultaneously in post of Octopress

How to see system load average in terminal with graphical representation

Forward all incoming emails to other SMTP server or gateway

Password prompt in single user mode is not secure : CentOS/Red Hat

set and unset line number in file with vi editor

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy