Help - Search - Members - Calendar
Full Version: .bash_profile Permissions
Linuxhelp > Support > Technical Support
I have added the following code as root to a users
.bash_profile file so they will be prompted with a menu
and depending on their choice will join another group,
but when the user1 has choosen 1, permission is
denied on the change group command presumably
because it is being executed by a simple user and not
root, it had worked outside the case statement at one stage but not inside and need it to work within
the case statement.

Could you please help find a way round it.
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc

# User specific environment and startup programs


export PATH

# menu

echo "-----------------------------------"
echo "Main Menu"
echo "------------------------------------"
echo "[1] Group1"
echo "[2] Group2"
echo "[3] Group3"
echo "[4] Group4"
echo "[5] Exit"
echo -n "Enter your menu choice [1-5]: "
read yourch
case $yourch in
1) gpasswd -a user1 group1;;
2) echo "Group2"; read;;
3) echo "Group3"; read;;
4) echo "Group4"; read;;
5) exit 0;;
*) echo " Bad choice, choose again"; read;;
As you said, when a user logs into their shell, everything in the .bash_profile is run as user only. Therefore, any change of groups cannot be done in this method, unless you want to give users permissions that you may not really want them to have. I think that as a sysadmin, you would want to have tighter control over what group a user is in. You may have to look for a different method of acheiving your goal.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2018 Invision Power Services, Inc.