Sudo: sorry, you must have a tty to run sudo

Source: Internet
Author: User

Solve sudo: sorry, you must have a tty to run sudo a few days ago encountered a problem, calling another shell in one terminal is always unable to execute, and then caught the error message sudo: sorry, you must have a tty to run sudo. Later, I learned on the Internet that the solution is as follows: 1. edit/etc/sudoers 1) Defaults requiretty and change it to # Defaults requiretty, indicating that the terminal does not need to be controlled. 2) Defaults requiretty, changed to Defaults: nobody! Requiretty, indicating that only the nobody user does not need to control the terminal. If it is changed to Defaults: % nobody! Requiretty, indicating that only the nobody group does not need to control the terminal. In fact, you only need to comment out) Defaults requiretty. Indicates that the terminal is not opened during execution. However, some shells must have terminals before execution. This is obviously not acceptable. Later, I found another article. The following is a copy, which is used only after record. Some programs/scripts may be executed in environments without control terminals (such as Daemon or setsid-enabled programs when the system starts services), but this program may need to be controlled by terminals, how can this be done? For example, we started a service in linux, but there was a program (old systemtap) in the middle) sudo is used, but sudo needs to control the terminal (of course, you can modify the sudo configuration file, but this is not user-friendly) Example: (the program started by setsid will lose the control Terminal) # setsid sudo lssudo: sorry, you must have a tty to run sudo (if your system does not output this sentence, that is, The sudo configuration file of your system allows sudo to be in this, please make sure that Defaults requiretty has been set) when there is no control interruption, open the control terminal is like this: # setsid head-c 0/dev/ttyhead: cannot open '/dev/tty' for reading: No such device or address to solve this problem, you should use the ability to create (pseudo) control the terminal program to start your program such as: script, keep CT such as: # setsid script-c "sudo ls"/dev/null or: # setsid login CT-c 'spawn sudo ls; login ct' # Open the control terminal successfully: # setsid script-c 'head-c 0/dev/tty '/dev/null # setsid expect CT-C' spawn head-c 0/dev/tty; except CT ', there is a strange bug in the combination of setsid and script. During this time, I was very depression, so it was quite useless for scripts and reverse CT.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.