How to use newgrp or sg in user mode without password prompt?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use newgrp or sg in user mode without password prompt?
# 1  
Old 08-13-2012
How to use newgrp or sg in user mode without password prompt?

Hi,

Is it possible to call newgrp or sg from user mode without password prompt in a Linux script?

Thank you.

hce
# 2  
Old 08-15-2012
sg actually executes login, newgrp does the same. The password you have to enter is in the /etc/gshadow file.

If this is really important you will have to write a C program that calls setgid() or setegid() and then calls exec()/fork() into a new process. The program will have to be marked with setgid, special file permissions mask.

If you really need this, then we can put up an example C program for you. You will need root access to get it working. It also makes a potentially big security hole.
# 3  
Old 08-15-2012
The sudo command is ideal for this type of thing, you can run commands or a shell as another group with or without password prompts. You system admin can limit access to particular command(s) from certain users or group.

example:

Code:
sudo -g other_grp /usr/local/bin/somecmd

/etc/sudoers entry to allow user hce to execute /usr/local/bin/somecmd as group other_grp without password:
Code:
hce ALL=(:other_grp) NOPASSWD:  /usr/local/bin/somecmd

You could even put something in your somecmd script to check group and execute it's self with sudo:
Code:
GRP=$(id -gn)
if [ "$GRP"  != "other_grp" ]
then
    exec sudo -u other_grp $0 $@
fi


Last edited by Chubler_XL; 08-15-2012 at 06:28 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass password and prompt user for IP address while doing ssh and scp?

Hi All, I want to copy /.ssh/OM.pub file from source to destination. Here source IP address, username and password is always fixed. Whereas destination server IP address, password always gets changed. From destination server :- I am trying to write a script in which it should log in to... (3 Replies)
Discussion started by: madhur.baharani
3 Replies

2. Solaris

Need to SC prompt from maintanance mode

Hi All, My server is at maintanace mode and i dont have root password. how can i go back to SC prompt from here. Ctrl+d is not working to bypass the activity. Root password for system maintenance (control-d to bypass): Login incorrect Root password for system maintenance (control-d to bypass): (7 Replies)
Discussion started by: Naveen.6025
7 Replies

3. Solaris

Solaris machine is at # prompt not able to login in GUI mode

Solaris machine is at # prompt not able to login in GUI mode : I want to login solaris server in GUI mode from # prompt. ---------- Post updated 12-30-11 at 11:36 AM ---------- Previous update was 12-29-11 at 02:23 PM ---------- Hi, Please send me some guidelines regarding this.... as... (2 Replies)
Discussion started by: sunray
2 Replies

4. AIX

Single user mode password

Hi, How to check whether the single user mode is password protected or not?By default, while entering in to single user mode, Os is not asking for login credentails. How can i enable it. Kindly help Rgds, kmvinay (2 Replies)
Discussion started by: kmvinay
2 Replies

5. Linux

SSH user equivalency still prompt for password

Hi All, I've followed the exact same steps of how to setup and enable SSH user equivalent including the right permission, but when I "ssh" it still prompts for password. Could you help to see what I did wrong? I appreciate any helps. :confused: server1.com:/u01/oracle RAC1 > mkdir... (2 Replies)
Discussion started by: Beginer0705
2 Replies

6. UNIX for Dummies Questions & Answers

change user> to user@host> ssh prompt

Hi, I was wondering how to change the prompt for my ssh login. At the moment it is like user> while I'd like it to be as user@host> It is in the .bash_profile or .ssh ??? Thanks (2 Replies)
Discussion started by: pmasterkim
2 Replies

7. UNIX for Dummies Questions & Answers

single user mode - user accounts passwords

hello ppl, someone must be able to help with this --> I have an old NCR tower 32 with an ADDS terminal running a unix version 020102 (Im not sure if thats correct but its unix for sure). I have no user names and no passwords and need to login to read a tape. Is there any way to do that? I hear... (3 Replies)
Discussion started by: orestis
3 Replies

8. UNIX for Dummies Questions & Answers

rsh as super user without password prompt

Dear forum, First off, I'm using Solaris 5.6 UNIX. I'm trying to write a script which will connect to remote computers on a network (by specific IP's from a hosts file) and will run a separate script which is installed in each of the remote computers. My problem is that to run the script in the... (1 Reply)
Discussion started by: TheMightyUrrrrf
1 Replies

9. IP Networking

Unable to get password prompt

Hi I am using a Solaris 2.5.1 and i am unable to logon on the console. When i key in say, root on the login prompt, it does not prompt me for password but instead return to the login prompt again. Please help. thanks (2 Replies)
Discussion started by: owls
2 Replies
Login or Register to Ask a Question