LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-21-2022, 05:42 PM   #1
rockb
LQ Newbie
 
Registered: Feb 2022
Posts: 2

Rep: Reputation: 0
Include sudo password with sudo -s command


I am working on an app to pull information from a remote Linux system. I am using vb.net and the Renci.SshNet library.

Everything works fine until I have to run a command that requires sudo. When using powershell I just start the whole process with sudo -s then put in the password but sending the password after the sudo -s sommand with the Renci library does not seem to work.

Is there a way to send the password at the same time as the sudo -s command?
 
Old 02-21-2022, 07:18 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,152

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
very unsafe:
Code:
echo yourpasssord|sudo -S /path/to/command
 
Old 02-21-2022, 09:31 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
ssh-keys is the std soln to this sort of requirement : eg https://www.cyberciti.biz/faq/how-to...on-linux-unix/
 
Old 02-22-2022, 02:13 PM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
^ Unless they enable ssh root login I don't see how this has any bearing on OP's problem.

Unfortunately I know nothing of this Renci library or why it "does not seem to work".

A purely remote and sufficiently safe solution could be to allow this specific user to run this specific command in this specific scenario via a carefully crafted /etc/sudoers rule.
 
Old 02-22-2022, 06:22 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well unless I misunderstood
Quote:
app to pull information from a remote Linux system
That would require ssh-keys to login, although having to then sudo as well would be tricky..
I've never had to try that myself.

Usually either the caller had the root login key (for internal trusted system only), or the remote service acct can be logged into, so sudo wasn't necessary.
 
Old 02-23-2022, 01:15 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,918

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
in that case I would rather try to set a passwordless sudo (post #4). Or use ssh key with sshd (post #5).
But what I don't understand exactly where do you need it? In your powershell session (in that case you can try to use "run as admin"), or on the remote linux box?
 
Old 02-23-2022, 10:13 AM   #7
rockb
LQ Newbie
 
Registered: Feb 2022
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Keith Hedger View Post
very unsafe:
Code:
echo yourpasssord|sudo -S /path/to/command
When I test this using Putty I am still prompted for password.

To address some of the other Comments/Questions

Renci is a library you can import into Visual Studio that provides SSH capability to your VB App.

The system I am trying to pull the information from will actually be many systems that are fielded all over the world. They are not connected to the internet or any external network for that matter. The end users have no admin access and in fact cannot even access the OS interface itself. The system boots to a custom GUI to control items on its closed network. There is a LAN port that is used to connect a laptop for configurations and updates.

We have a requirement to pull information (logs, system configuration information, etc) from the systems periodically to review. We do not want to provide admin access to these systems to the end users because they do not need that for their day to day operations. The only thing they will need admin access for is to pull this information so my thought was to send out a laptop to the sites that they can plug into that configuration port, log in, double click an icon on the desktop, let the app pull all the info it needs, then they send the laptop back. Before you say that is going to be costly, it is far more economical that putting someone on a plane to fly all over the world for 20 minutes of work at each site.

I know it is possible as there is an app that does what I want but it only pulls about half of what I need.

Modification of the Linux box is difficult as the vendor is hesitant to make any changes because "it works the way it is".
 
Old 02-23-2022, 11:09 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,918

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
that is exactly the private/public key pair. Only the "owner" of this key will be allowed to do admin activities. There is no need to install additional software, only the official sshd required (and some configuration).
Otherwise it is still unclear how do you want to access that information from your windows host and why only the half of the data can be pulled.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sudo password different from non-sudo password edrom Linux - Newbie 2 04-20-2012 03:00 PM
Differences between /usr/include/* and linux/include/* simopal6 Linux - General 2 08-26-2007 03:41 AM
changing include directories - /usr/local/include quep_fly Linux - Newbie 6 08-12-2007 04:36 PM
which headers usr/include/ or /usr/include/nptl/? Chris.Rector Linux - Enterprise 0 02-02-2007 01:40 PM
include/linux/types.h and include/linux/posix_types.h kpachopoulos Programming 2 11-26-2005 05:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 06:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration