Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

script to run synaptic as another user [SOLVED]

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
User avatar
sickpig
Posts: 589
Joined: 2019-01-23 10:34

script to run synaptic as another user [SOLVED]

#1 Post by sickpig »

[SOLVED] - tnx to a deleted post and of course everyone who replied

Folks,

I am logged in as user 'a' and I can run synaptic as user 'b' by

Code: Select all

su b
sudo synaptic
How can I achieve the above with a bash script?
Last edited by sickpig on 2019-06-30 21:55, edited 3 times in total.

User avatar
cds60601
df -h | participant
df -h | participant
Posts: 724
Joined: 2017-11-25 05:58
Location: Florida
Has thanked: 133 times
Been thanked: 64 times

Re: script to run synaptic as another user

#2 Post by cds60601 »

Probably notthe smartest way nor exactly what you want to do, but what I have done is this:

in my sudoers file:

Code: Select all

chris   ALL = NOPASSWD: ALL
Then I have a few simple alias setup:

Code: Select all

alias pacman='sudo apt $1'
alias pamac='sudo synaptic-pkexec &' 
I use pamac and pacman since I came off of Arch ;)
but this does what I need it to do. Again, not exactly what you are asking but I hope it lends to some ideas for you.

C
Supercalifragilisticexpialidocious

Wheelerof4te
Posts: 1454
Joined: 2015-08-30 20:14

Re: script to run synaptic as another user

#3 Post by Wheelerof4te »

Create an empty file with this content:

Code: Select all

#!/bin/bash
su b && sudo synaptic
Save the file and run it in Terminal. You can add the script to your $PATH, so that you can run it from anywhere. Google how to do that.
EDIT: It probably won't work, because doing su b will just leave you at the user's b shell. Also, it needs to be made executable first.

User avatar
sickpig
Posts: 589
Joined: 2019-01-23 10:34

Re: script to run synaptic as another user

#4 Post by sickpig »

thanks guys
@cds60601 appreciate your advise but I am wary of using NOPASSWD especially since I am hardening my system's security posture.

@Wheelerof4te, thank you kindly for the suggested option, i had been playing around several alternatives along those lines like

Code: Select all

su b -S /bin/sh -c /home/b/synaptic.sh (script to launch synaptic)
or 
gksudo -u b 'synaptic'
You have to do xhost +local: before running gksudo though to allow other user to share screen resources
they were not what I was after.

Then I swear I saw Head_on_a_Stick's post advising below

Code: Select all

su b -c '/usr/bin/synaptic-pkexec'
Excellent piece of advise. Bullseye. I can't c that post anymore (it was probably this message will self destruct once u see it kind of a thing)

I rolled with it and I discovered i can just run synaptic-pkexec no need for su or anything else. upon running synaptic-pkexec i was presented with a polkit prompt to input the admin password like below:
Image

this was no good because i had to change the user from a to b. one additional mouse click, now we cant have that can we?

then i asked internet and it provided

To set an user (say b) as an administrator for polkit, create a file in /etc/polkit-1/localauthority.conf.d/ (say 99-custom.conf), containing:

Code: Select all

[Configuration]
AdminIdentities=unix-user:b;unix-user:a
credit - https://askubuntu.com/questions/542397/ ... entication

am a very happy puppy now

Many thanks to Head_on_a_Stick. If not for your excellent how to articles and numerous helpful posts(even self destructing ones), I would have still been in Debian stone ages. Thanku thanku.
Last edited by sickpig on 2019-06-30 21:54, edited 1 time in total.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: script to run synaptic as another user

#5 Post by Head_on_a_Stick »

sickpig wrote:Then I swear I saw Head_on_a_Stick's post advising below

Code: Select all

su b -c '/usr/bin/synaptic-pkexec'
Excellent piece of advise. Bullseye. I can't c that post anymore (it was probably this message will self destruct once u see it kind of a thing)
I deleted the post because the su command requires a password but doesn't provide a graphical prompt window; I was looking for a better solution but I got distracted. FWIW using sudo's -U option with an entry in /etc/sudoers to obviate the need for a password would probably be the way but using pkexec alone makes more sense.

As an aside, it's better to always prefer POSIX (!#/bin/sh) scripts over bash unless you need any of bash's special features (called "bashisms") because /bin/sh is symlinked to dash in Debian and that is a faster, lighter, less buggy shell.

And please remove the "-tnx to HOAS" bit from the thread title, it may interfere with the SEO effect of the [SOLVED] tag and possibly also discourage the other people who helped out in this thread.
deadbang

User avatar
sickpig
Posts: 589
Joined: 2019-01-23 10:34

Re: script to run synaptic as another user

#6 Post by sickpig »

Head_on_a_Stick wrote:And please remove the "-tnx to HOAS" bit from the thread title, it may interfere with the SEO effect of the [SOLVED] tag and possibly also discourage the other people who helped out in this thread.
done, though I don't entirely agree that it would have discouraged anyone.

Post Reply