Cyberithub

Solved: "sudo: Sorry, you must have a tty to run sudo" Error on a Linux/Unix Using 2 Best Method

Advertisements

You might have seen "sudo: Sorry, you must have a tty to run sudo" Error on a Linux and Unix machine while trying to run some command or when trying to start some services. In this article, we will look into the error and the various methods which can be used to solve this error.

What is sudo 

sudo is a command Line utility in Linux based systems which allows a command to be run with privileged user access i.e with root access. For any command to be run with sudo access you need to provide this access to the User through /etc/sudoers file. You can check more on Step by Step: How to Add User to Sudoers to provide sudo access to the User.

Advertisements

What is TTY

TTY is basically known as teletypewriter also known as terminal. It is an interface to run Linux/Unix based commands. You can always find multiple number of TTY in your System. Whenever you run a command in your Linux/Unix Systems you need to provide input through the terminal and then you get the output in the same terminal.

Solved: "sudo: Sorry, you must have a tty to run sudo" Error on a Linux/Unix Using 2 Best Method 1

"sudo: Sorry, you must have a tty to run sudo" Error

Also Read: 41 Best Linux lsof command examples (How to Identify Open Files)

Advertisements

You will usually encounter this error when sudo does not have a terminal to run some command. If you are trying to start a service which in turn is running some command in backend with sudo access then you will be asked to allocate a tty to run the command through sudo access.

Another scenario could be when you are trying to run some sudo command on remote host which requires a password to run that command but there is no terminal assigned so it will again throw "sudo: Sorry, you must have a tty to run sudo" error as shown below. It is worth noting here that we are trying to connect remote host through root user and not through non-privileged user still we are able to see the same error.

Advertisements
[root@localhost ~]# ssh root@192.168.0.104 sudo ls -l
sudo: sorry, you must have a tty to run sudo

This error could also occur locally whenever you try to run some command with sudo access as shown below.

[root@localhost ~]# su -c 'sudo -l' centos
sudo: sorry, you must have a tty to run sudo

There are basically two different methods which you can use to solve this "sudo: Sorry, you must have a tty to run sudo" error as shown below.

Advertisements

Method 1: Use -t option with ssh command 

If you are getting "sudo: Sorry, you must have a tty to run sudo" error while trying to run sudo command on remote host then you need to use -t option with ssh command to provide pseduo terminal to run sudo command as shown below.

[root@localhost ~]# ssh -t root@192.168.0.104 sudo ls -l
total 1737405
-rw-r--r-- 1 root root 2048 Dec 23 2019 --exclude-file=hello.txt
-rw-r--r-- 1 root root 888888898 Jun 7 08:35 file.txt
-rw-r--r-- 1 root root 1798 Dec 23 2019 files.tar.bzip2
-rw-r--r-- 1 root root 3893 Dec 23 2019 hello.txt
-rwxr-xr-x 1 root root 4 Jun 9 21:48 pr.sh
-rw-r--r-- 1 root root 3893 Dec 23 2019 test.txt
-rw-r--r-- 1 root root 28 Jun 19 08:44 testfile.txt
Connection to 192.168.0.104 closed.

Method 2: Remove or Comment out "Defaults requiretty" Line in /etc/sudoers file

Second method which is also a permanent solution is to remove or comment "Defaults requiretty" Line in /etc/sudoers file as shown below.

[root@localhost ~]# grep -i requiretty /etc/sudoers
Defaults requiretty

You can simply put # mark at the beginning of Defaults requiretty Line to disable the requiretty option from /etc/sudoers file as shown below.

[root@localhost ~]# vi /etc/sudoers
....................................................

## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom

## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now

## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d
#Defaults requiretty

 

 

 

 

 

 

 

Popular Recommendations:-

How to Install PHP on Ubuntu 18.04

How to Install Ruby on Ubuntu 18.04 with Easy Steps

How to Install Ruby on CentOS/RedHat 7 in 5 Easy Steps

33 Practical Examples of ulimit command in Linux/Unix for Professionals

Install Node.js in 6 Easy Steps on Ubuntu 18.04

How to Install NVM for Node.js on Ubuntu 18.04

How to Limit CPU Limit of a Process Using CPULimit in Linux (RHEL/CentOS 7/8)

How to Install Rust Programming Language in Linux Using 6 Best Steps

How to Install LEMP Stack on CentOS 8

sudo : Sorry you must have a tty to run sudo

Leave a Comment