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 9100129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:47:28+00:00 2026-06-17T00:47:28+00:00

Java – Jsch sudo command. I am using Jsch and my task is to

  • 0

Java – Jsch sudo command.

I am using Jsch and my task is to login to server and run command as following

sudo su - bumboo

Using following code i am successfully able to connect but when i try to run command it gives me error sudo: sorry, you must have a tty to run sudo

Following is my code

public static Channel sudoBamboo(Session session, String sudo_pass) throws Exception {

        ChannelExec channel = (ChannelExec) session.openChannel("exec");
        //SUDO to bamboo user
        String command = "sudo su - bumboo";
        channel.setCommand(command);

        //InputStream in = channel.getInputStream();
        channel.setInputStream(null, true);

        OutputStream out = channel.getOutputStream();
        //channel.setErrStream(System.err);
        channel.setOutputStream(System.out, true);
        channel.setExtOutputStream(System.err, true);
        //Test change
        //channel.setPty(false);
        channel.connect();

        out.write((sudo_pass + "\n").getBytes());
        out.flush();

        return channel;
    }

jsch in sudo.java available example they advised to use

// man sudo
      //   -S  The -S (stdin) option causes sudo to read the password from the
      //       standard input instead of the terminal device.
      //   -p  The -p (prompt) option allows you to override the default
      //       password prompt and use a custom one.
      ((ChannelExec)channel).setCommand("sudo -S -p '' "+command);

but when i run command like "sudo -S -p - su bamboo" still gives me the same error

any help appreciated.

  • 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-17T00:47:29+00:00Added an answer on June 17, 2026 at 12:47 am

    It worked for me

    String command = "sudo su - bumboo";
    channel.setPty(true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Java noob question: Consider the following C array and initializer code: struct { int
java - xpath - pom.xml I am using following pom.xml file as xml dom
Java class in *.bat can be run by double click but not task scheduler.
Java Experts , Please look into the below split command code and let me
Java newbie here, I am trying to find the output of the following chunk
Java uses a combination of compilation and interpretation. It compiles the source code into
Java code executing a Ruby script: ruby = new ScriptingContainer(LocalVariableBehavior.PERSISTENT); ruby.put(MyJavaClass, MyJavaClass.class); ruby.runScriptlet(readFile(Test.rb)); MyJavaClass
java 1.4 Sql server 2000 i am taking input of sql query (for validation
JAVA Code Here is some part of my code that I have written in
Java Code : package Package; public class IntArray { private native int sumArray(int[] arr);

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.