Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8781373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:17:06+00:00 2026-06-13T20:17:06+00:00

Ok, here is a tricky question: First, I have a very small C application

  • 0

Ok, here is a tricky question:

First, I have a very small C application that runs in an Unix machine. This application gets two arguments and tries to execute an .sh file in a Linux (Ubuntu) machine, like this:

./myapp luke leia

Ok, now the C code executes more or less this:

char temp[512];
sprintf(temp, "ssh user@server \"sh \\$HOME/save.sh %s %s\"", argv[1], argv[2]);
system((char *)temp);

As you can see, it opens a connection to my Linux server and executes a batch script in the home folder of my ‘user’. This is how it looks like when I try directly in my terminal:

ssh user@server "sh \$HOME/save.sh luke leia"

In my Unix side, I am asked for a password for the SSH, and it works just fine. I get all the echoes from the save.sh file in my Unix machine and it works well, except if I need a sudo permission. So I tried this in my server:

  1. Using sudo visudo in the server, below the line that says %sudo ALL=(ALL) ALL I put:

    %user ALL=(ALL) NOPASSWD: /home/user/save.sh

  2. My save.sh looks like this:

#! /bin/bash
sudo echo "[save action] args: ${1} , ${2}" >> /somewhere/save.log;
echo "${1} and ${2} are brother and sister.";
  1. My folder “somewhere” belongs to root, so normally my ‘user’ can’t save it. So I changed the code in my application to handle this command instead:

ssh user@server "sudo sh \$HOME/save.sh luke leia"

Now I get this error:

sudo: no tty present and no askpass program specified

Which is the best way to trigger this script using sudo and not being prompted with root password? I tried using -t, but is asks for root password. Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:17:07+00:00Added an answer on June 13, 2026 at 8:17 pm

    Solution that comes to my mind is to provide the root passowrd of “server” machine as additional parameter (argv[3]) in your C program:

    char temp[1024];
    snprintf(temp, sizeof(temp), "ssh user@server \"echo %s | sudo -S -s \\$HOME/save.sh %s %s\"", argv[3], argv[1], argv[2]);
    system((char *)temp);
    

    -S for sudo means that password will be provided via stdin, so no user interaction should be needed. It’s theoretical solution (I do not have time to check it – sorry) check it for your self & please tell as whether it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here's a tricky question... I have default styled input fields (no css added, just
I have what I think is a tricky question, but hopefully someone on here
I have looked around here to see if somebody has asked this question before
Here's a tricky normalization/SQL/Database Design question that has been puzzling us. I hope I
Here's a tricky iPhone problem I've been working on. I have three UIScrollViews on
You can see the example here: http://jsfiddle.net/8EHED/8/ This is a tricky problem because I
Is there some trick that I'm missing here? I've created a templated control, very
Alright, I have some weird behavior and this question goes to the people out
I have an application that started life as an MVC (1.0) app in Visual
first off, this question is not related to a specific language - I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.