script to run synaptic as another user [SOLVED]

Need help with C, C++, perl, python, etc?

script to run synaptic as another user [SOLVED]

Postby sickpig » 2019-06-29 02:27

[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.
haven = Sir P.G. Wodehouse's books. U havent lived unless u have read one :)
User avatar
sickpig
 
Posts: 314
Joined: 2019-01-23 10:34

Re: script to run synaptic as another user

Postby cds60601 » 2019-06-29 13:12

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
Server: Debian 9, Workstation: Arch
Laptop: Debian SID (i3), Pi: Raspbian (Pi-Hole)
User avatar
cds60601
 
Posts: 177
Joined: 2017-11-25 05:58
Location: Tampa, Florida

Re: script to run synaptic as another user

Postby Wheelerof4te » 2019-06-29 13:17

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.
Wheelerof4te
 
Posts: 1422
Joined: 2015-08-30 20:14

Re: script to run synaptic as another user

Postby sickpig » 2019-06-29 22:38

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.
haven = Sir P.G. Wodehouse's books. U havent lived unless u have read one :)
User avatar
sickpig
 
Posts: 314
Joined: 2019-01-23 10:34

Re: script to run synaptic as another user

Postby Head_on_a_Stick » 2019-06-30 12:49

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.
User avatar
Head_on_a_Stick
 
Posts: 10346
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: script to run synaptic as another user

Postby sickpig » 2019-06-30 22:02

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.
haven = Sir P.G. Wodehouse's books. U havent lived unless u have read one :)
User avatar
sickpig
 
Posts: 314
Joined: 2019-01-23 10:34


Return to Programming

Who is online

Users browsing this forum: No registered users and 7 guests

fashionable