Re: run perl script to configure remote computer using sudo

2018-11-08 Thread Digimer
On 2018-11-08 9:51 p.m., D&R wrote:
> I have tried several ways to connect to remote computer:
> 
> $SERVER = qx{ssh -o ConnectTimeout=2 -o ControlPersist=yes $user\@$server
> "sudo hostname| cut -d "." -f1"}; chomp ($SERVER);
> 
> but commands that have metacharacters, especially the single quote, I can not
> get to work.
> 
> I can run the following from perl after ssh connection with single quotes
> included:
> 
> $ssh = Net::OpenSSH->new("$user\@$server");
> $CMD = "grep -c alias cp='cp -f' /etc/bashrc";
> $fh = $ssh->pipe_out($CMD);
> 
> while (<$fh>) {
> $OUTPUT .= $_;
> }
> chomp ($OUTPUT);
> 
> and it works.
> 
> But if add 'sudo' for cases where I need to read a file that the login user
> does not have permissions for -- I can not get it to work.
> 
> I have searched and tried a number of recommendations and it either fails with
> a permission error or locks up or gives grep errors.
> 
> Thanks in advance,
> 
> David

Hi David,

  We have a program that does a lot of SSH'ing, and wrote a perl module
(as part of a larger project). We're using Net::SSH2 as the back-end. We
also use rsync (over ssh) to move files around.

  I can't speak to your specific issue, but perhaps our code can give
you some ideas?

https://github.com/digimer/anvil/blob/master/Anvil/Tools/Remote.pm

  There, look at the 'call()' method (line 258 in the current commit).
There is a bunch of sanity checking you can probably ignore, with the
most interesting bit starting at (current) line 414.

  Here is a condensed version (obviously untested) to hopefully make the
key steps easier to follow (our program uses translation so the user
messages are not immediately obvious in the source).


$ssh_fh = Net::SSH2->new(timeout => 1000);
if (not $ssh_fh->connect($target, $port))
{
# examine '$@' for why it failed.
die;
}

if (not $ssh_fh->auth_password($remote_user, $password))
{
# Failed with password, try again in case passwordless ssh works
if ($ssh_fh->auth_publickey($user, $public_key, $private_key))
{
# That worked.
}
else
{
# No luck
die;
}
}
else
{
# Connected with password successfully
}

# We need to open a channel every time for 'exec' calls. We want to keep
# blocking off, but we need to enable it for the channel() call.
$ssh_fh->blocking(1);
my $channel = $ssh_fh->channel() or $ssh_fh->die_with_error;
if (not $channel)
{
# Try again a few times and die if none work...
}
$ssh_fh->blocking(0);
$channel->exec("$shell_call");
my @poll = {
handle => $channel,
events => [qw/in err/],
};

# We'll store the STDOUT and STDERR data here.
my $stdout = "";
my $stderr = "";

# Now collect the data.
while(1)
{
$ssh_fh->poll(250, \@poll);

# Read in anything from STDOUT
while($channel->read(my $chunk, 80))
{
$stdout .= $chunk;
}
while ($stdout =~ s/^(.*)\n//)
{
my $line = $1;
push @{$stdout_output}, $line;
}

# Read in anything from STDERR
while($channel->read(my $chunk, 80, 1))
{
$stderr .= $chunk;
}
while ($stderr =~ s/^(.*)\n//)
{
my $line = $1;
push @{$stderr_output}, $line;
}

# Exit when we get the end-of-file.
last if $channel->eof;
}


-- 
Digimer
Papers and Projects: https://alteeve.com/w/
"I am, somehow, less interested in the weight and convolutions of
Einstein’s brain than in the near certainty that people of equal talent
have lived and died in cotton fields and sweatshops." - Stephen Jay Gould
___
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org


run perl script to configure remote computer using sudo

2018-11-08 Thread
I have tried several ways to connect to remote computer:

$SERVER = qx{ssh -o ConnectTimeout=2 -o ControlPersist=yes $user\@$server
"sudo hostname| cut -d "." -f1"}; chomp ($SERVER);

but commands that have metacharacters, especially the single quote, I can not
get to work.

I can run the following from perl after ssh connection with single quotes
included:

$ssh = Net::OpenSSH->new("$user\@$server");
$CMD = "grep -c alias cp='cp -f' /etc/bashrc";
$fh = $ssh->pipe_out($CMD);

while (<$fh>) {
$OUTPUT .= $_;
}
chomp ($OUTPUT);

and it works.

But if add 'sudo' for cases where I need to read a file that the login user
does not have permissions for -- I can not get it to work.

I have searched and tried a number of recommendations and it either fails with
a permission error or locks up or gives grep errors.

Thanks in advance,

David
___
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org


Re: KDE using sudo instead of su

2014-05-08 Thread Emmett Culley
On 05/02/2014 08:42 AM, Rex Dieter wrote:
> Emmett Culley wrote:
> 
>> On 04/30/2014 10:27 AM, Joe Zeff wrote:
>>> On 04/30/2014 08:25 AM, Emmett Culley wrote:
 Any ideas how to get apps to require the root password instead of my
 user password?
>>>
>>> Take yourself out of wheel.
>> I was in the users group, but not in the wheel group.
>>
>> Also, I have all sudoers disabled except for root.
>>
>> Still, I get prompted for my users password.  Something to do with polkit?
> 
> Yes polkit.  The curious thing is that polkit default configuration is
> supposed to work as you describe:
> 
> admin user (in wheel) group: allow user password
> non admin user: require root password
> 
> -- Rex
> 
I got it fixed so that I get prompted for root password, but yumex still 
requires my user password.  There are no sudoers rules enabled except root.

What's so special about yumex?

Emmett
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org


Re: KDE using sudo instead of su

2014-05-02 Thread Rex Dieter
Emmett Culley wrote:

> On 04/30/2014 10:27 AM, Joe Zeff wrote:
>> On 04/30/2014 08:25 AM, Emmett Culley wrote:
>>> Any ideas how to get apps to require the root password instead of my
>>> user password?
>> 
>> Take yourself out of wheel.
> I was in the users group, but not in the wheel group.
> 
> Also, I have all sudoers disabled except for root.
> 
> Still, I get prompted for my users password.  Something to do with polkit?

Yes polkit.  The curious thing is that polkit default configuration is 
supposed to work as you describe:

admin user (in wheel) group: allow user password
non admin user: require root password

-- Rex

-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org


Re: KDE using sudo instead of su

2014-05-01 Thread Emmett Culley
On 04/30/2014 10:27 AM, Joe Zeff wrote:
> On 04/30/2014 08:25 AM, Emmett Culley wrote:
>> Any ideas how to get apps to require the root password instead of my user 
>> password?
> 
> Take yourself out of wheel.
I was in the users group, but not in the wheel group.

Also, I have all sudoers disabled except for root.

Still, I get prompted for my users password.  Something to do with polkit?

Emmett
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org


Re: KDE using sudo instead of su

2014-04-30 Thread Joe Zeff

On 04/30/2014 08:25 AM, Emmett Culley wrote:

Any ideas how to get apps to require the root password instead of my user 
password?


Take yourself out of wheel.
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org


Re: KDE using sudo instead of su

2014-04-30 Thread Tim
On Wed, 2014-04-30 at 08:25 -0700, Emmett Culley wrote:
> It is interesting that my other workstation works differently. That
> is, yumex doesn't prompt for the root password until it is about to do
> something that requires root permissison.  But it is asking for the
> root password, not my user password, as are all other apps that
> require root permissions.
>  
> Any ideas how to get apps to require the root password instead of my
> user password?

You probably didn't set up that user with yourself in the "wheel" group,
which sets up the user for use with sudo, in a simple manner.  In
windows-parlance, an admin user.

-- 
tim@localhost ~]$ uname -rsvp

Linux 3.13.10-200.fc20.i686 #1 SMP Mon Apr 14 21:00:56 UTC 2014 i686

All mail to my mailbox is automatically deleted, there is no point trying
to privately email me, I will only read messages posted to the public lists.

George Orwell's '1984' was supposed to be a warning against tyranny, not
a set of instructions for supposedly democratic governments.

-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org


KDE using sudo instead of su

2014-04-30 Thread Emmett Culley
I've noticed recently that when I run yumex, or most any other app that needs 
root permission, from the launcher menu, I am prompted for my user password, 
instead of the root password. So I assume sudo is being used instead of su.

The "run backend with sudo" is not checked in yumex preferences.  If I set the 
menu item to execute as root and add --root to the yumex call I get the root 
pasword request but then yumex doesn't start.

It is interesting that my other workstation works differently. That is, yumex 
doesn't prompt for the root password until it is about to do something that 
requires root permissison.  But it is asking for the root password, not my user 
password, as are all other apps that require root permissions.

Any ideas how to get apps to require the root password instead of my user 
password?

Emmett
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org


Re: using sudo

2010-05-24 Thread Kevin Fenzi
On Mon, 24 May 2010 16:11:27 -0400
terry  wrote:

> I've looked  through the systems > administation but cannot figure
> how to put myself in the file where I can use  say sudo yum something 
> without having to use su ,  passwd each time I need to be root
> thank you.

http://fedorasolved.org/post-install-solutions/sudo/

Might be of help. 

kevin


signature.asc
Description: PGP signature
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


Re: using sudo

2010-05-24 Thread kalinix
On Mon, 2010-05-24 at 17:35 -0500, Steven Stern wrote:

> In reality, the reason for requiring a sudo password challenge is that
> you don't want someone who walks up to your computer to have root privs.
> At the very least, they have to know your password to use sudo.
> 
> 
> -- 
> -- Steve


Now, this is a little bit different than "Are you sure thing" :)

Over and out.


Calin

Key fingerprint = 37B8 0DA5 9B2A 8554 FB2B 4145 5DC1 15DD A3EF E857

=
poverty, n.: An unfortunate state that persists as long as anyone lacks
anything he would like to have.
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


Re: using sudo

2010-05-24 Thread Steven Stern
On 05/24/2010 05:17 PM, kalinix wrote:
> On Mon, 2010-05-24 at 16:07 -0500, Steven Stern wrote:
>> Evil foolishness!  One should always require a password for sudo.  It's
>> like an "Are You Sure?" prompt.
> 
> Yeah, and why not put script that ask you hundreds of times, "Are you
> sure?" And then, on one hundred an one time let you do exactly what you
> wanted to do in the first place.
> That's M$ crap. Linux users are much more smarter than that. Well, at
> least a large part of them :D
> 
> 

I'm always sure, even as I delete an entire partition.  Oops.

In reality, the reason for requiring a sudo password challenge is that
you don't want someone who walks up to your computer to have root privs.
At the very least, they have to know your password to use sudo.


-- 
-- Steve
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


Re: using sudo

2010-05-24 Thread kalinix
On Mon, 2010-05-24 at 16:07 -0500, Steven Stern wrote:

> Evil foolishness!  One should always require a password for sudo.  It's
> like an "Are You Sure?" prompt.


Yeah, and why not put script that ask you hundreds of times, "Are you
sure?" And then, on one hundred an one time let you do exactly what you
wanted to do in the first place.
That's M$ crap. Linux users are much more smarter than that. Well, at
least a large part of them :D


Calin

Key fingerprint = 37B8 0DA5 9B2A 8554 FB2B 4145 5DC1 15DD A3EF E857

=
You have a deep appreciation of the arts and music.
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


Re: using sudo

2010-05-24 Thread Richard Shaw
On Mon, May 24, 2010 at 4:07 PM, Steven Stern
 wrote:
> On 05/24/2010 03:48 PM, Richard Shaw wrote:
>> On Mon, May 24, 2010 at 3:11 PM, terry  wrote:
>>> I've looked  through the systems > administation but cannot figure how
>>> to put myself in the file where I can use  say sudo yum something
>>> without having to use su ,  passwd each time I need to be root
>>> thank you.
>>
>> I assume that you would like it where the sudo does not require a
>> password either? In that case su into a root terminal login and type
>> "visudo". Twards the bottom of the file there is a line that is
>> commented out that allows all users of the "wheel" group to access all
>> commands without a password. Uncomment the line and save the file,
>> i.e. ":wq". Use the GUI User and Groups control panel to add yourself
>> to the "wheel" group and logout and back in. If you did everything
>> correctly then you should be able to "sudo " anything and it
>> should work without prompting for a password.
>>
>
>
> Evil foolishness!  One should always require a password for sudo.  It's
> like an "Are You Sure?" prompt.

I don't setup mine with the NOPASSWD option, but he asked... :)

Richard
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


Re: using sudo

2010-05-24 Thread Sam Sharpe
On 24 May 2010 22:07, Steven Stern  wrote:
> On 05/24/2010 03:48 PM, Richard Shaw wrote:
>> Towards the bottom of the file there is a line that is
>> commented out that allows all users of the "wheel" group to access all
>> commands without a password.
>
> Evil foolishness!  One should always require a password for sudo.  It's
> like an "Are You Sure?" prompt.

Of course I am sure, that's why I prefixed the command with the word "sudo" ;oP

-- 
Sam
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


Re: using sudo

2010-05-24 Thread Steven Stern
On 05/24/2010 03:48 PM, Richard Shaw wrote:
> On Mon, May 24, 2010 at 3:11 PM, terry  wrote:
>> I've looked  through the systems > administation but cannot figure how
>> to put myself in the file where I can use  say sudo yum something
>> without having to use su ,  passwd each time I need to be root
>> thank you.
> 
> I assume that you would like it where the sudo does not require a
> password either? In that case su into a root terminal login and type
> "visudo". Twards the bottom of the file there is a line that is
> commented out that allows all users of the "wheel" group to access all
> commands without a password. Uncomment the line and save the file,
> i.e. ":wq". Use the GUI User and Groups control panel to add yourself
> to the "wheel" group and logout and back in. If you did everything
> correctly then you should be able to "sudo " anything and it
> should work without prompting for a password.
> 


Evil foolishness!  One should always require a password for sudo.  It's
like an "Are You Sure?" prompt.


-- 
-- Steve
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


Re: using sudo

2010-05-24 Thread Peter Larsen
On Mon, 2010-05-24 at 16:11 -0400, terry wrote:
> I've looked  through the systems > administation but cannot figure how 
> to put myself in the file where I can use  say sudo yum something 
> without having to use su ,  passwd each time I need to be root
> thank you.

alt-f2 
su -c visudo

Sudo isn't a gui app, so there's no gui option to maintain it.

-- 
Best Regards
  Peter Larsen

Wise words of the day:
MSDOS didn't get as bad as it is overnight -- it took over ten years
of careful development.
-- dmegg...@aix1.uottawa.ca


signature.asc
Description: This is a digitally signed message part
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


Re: using sudo

2010-05-24 Thread Richard Shaw
On Mon, May 24, 2010 at 3:11 PM, terry  wrote:
> I've looked  through the systems > administation but cannot figure how
> to put myself in the file where I can use  say sudo yum something
> without having to use su ,  passwd each time I need to be root
> thank you.

I assume that you would like it where the sudo does not require a
password either? In that case su into a root terminal login and type
"visudo". Twards the bottom of the file there is a line that is
commented out that allows all users of the "wheel" group to access all
commands without a password. Uncomment the line and save the file,
i.e. ":wq". Use the GUI User and Groups control panel to add yourself
to the "wheel" group and logout and back in. If you did everything
correctly then you should be able to "sudo " anything and it
should work without prompting for a password.

Richard
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


Re: using sudo

2010-05-24 Thread Erik P. Olsen
On 24/05/10 22:11, terry wrote:
> I've looked  through the systems>  administation but cannot figure how
> to put myself in the file where I can use  say sudo yum something
> without having to use su ,  passwd each time I need to be root
> thank you.

Look into /etc/sudoers. That's where you enable sudo.

-- 
Erik
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


Re: using sudo

2010-05-24 Thread David García Granda
Hi Terry,

> I've looked  through the systems > administation but cannot figure how
> to put myself in the file where I can use  say sudo yum something
> without having to use su ,  passwd each time I need to be root

You need to edit /etc/sudoers file. Check man sudoers for more information.

HTH,

David
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


using sudo

2010-05-24 Thread terry
I've looked  through the systems > administation but cannot figure how 
to put myself in the file where I can use  say sudo yum something 
without having to use su ,  passwd each time I need to be root
thank you.
-- 
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines