Ubuntu: Start Up Terminal With Command; Then Go To Bash Shell



Question:

Via a desktop shortcut, an admin will launch a shell as another user. The user should go into the shell with no elevated privileges, but execute the first command with elevated privileges. In the end, the user should be in non-privileged shell that is kept open for further use.

How do I do this?

Question Edited For WIP Answer.

Latest test:

gksudo "gnome-terminal --execute bash -c 'boss "apt-get update"; bash'"  

Does not work.

What follows is the answer thanks to Laurent helping me brainstorm. Unfortunately my situation was too sophisticated for me to express well.

I have an admin user who never goes online. He uses proxy users to fetch things and do his bidding. The user named update is in the sudoers file and is allowed to apt-get with NOPASSWD. admin wants a shortcut leading to a gnome-terminal that automatically calls apt-get update upon execution because admin wants to install something right after that, something that can't be predicted to be put in a script. Auto updates won't work for admin, because admin is fire-walled from the internet and is forced to hire goons for system updates and fetching other downloads.

Thank you Laurent for leading me to the right answer! Here it is:

gksudo -u update "gnome-terminal --execute bash -c 'sudo apt-get update;bash'"  


Solution:1

You have to make the launcher using this:

gksudo "gnome-terminal --execute bash -c 'apt-get "update"; bash'"  

Edit after definition of not opening terminal as root (to leave it in unelevated privileges after running the command:

gnome-terminal --execute bash -c "sudo apt-get 'update';bash"  

This way, the terminal will open, ask for password (if needed) and continue.

Obs: if your command doesn't need sudo, just remove it from the command. I used gksudo on the first answer because your example was using it so I thought it was needed for the whole process (and leaving the terminal in elevated privileges).

Both launcher will work but 1st one will ask password with in GUI and run the whole process as sudo leaving the terminal open in "sudo mode" and 2nd launcher will open terminal, ask for password there, run command as sudo and leave terminal in "user mode".

You can edit sudo (with visudo) to make it use sudo without password (and maybe restrict this user to run only a few command if not only this one) but this is not the most recommended thing to do.

If you can give more info about what you are trying to do, maybe there is a different way to do it? (can be better... or worse... of course :) )


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »