linux - sudo 抱歉,你必须有 tty 才能运行 sudo

标签 linux bash

<分区>

我已经编写了一个 bash 脚本,它可以连接到每台机器并运行一组命令。我正在使用该机器上具有 sudo privlidges 的用户 iis。但是,当我运行 sudo yum 命令时,我得到 sudo: 抱歉,你必须有一个 tty 才能运行 sudo。

不确定哪里出了问题?我正在使用 -t 命令强制,但它仍然不起作用

脚本

#!/bin/bash
INPUT=ccidetails.csv
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read privateip password
do
echo $privateip
scp /home/Data/Test.c iis@$privateip:/tmp
sshpass -p$password </dev/null ssh -t -o "StrictHostKeyChecking no" iis@$privateip "

hostname
cd /tmp
gcc Test.c -o TEST
./TEST
sudo yum -y update glibc
gcc Test.c -o TEST
./TEST
exit

" >> output.txt

done < $INPUT
IFS=$OLDIFS

错误:

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

最佳答案

在远程主机上,在/etc/sudoers 上注释以下行:

 grep tty /etc/sudoers
#Defaults    requiretty

这将使您能够继续。确保您了解这样做的后果:

man sudoers | grep -i requiretty  -A 5
       requiretty      If set, sudo will only run when the user is logged in
                       to a real tty.  When this flag is set, sudo can only be
                       run from a login session and not via other means such
                       as cron(8) or cgi-bin scripts.  This flag is off by
                       default.

如果您不想全局禁用 requiretty,您可以为特定用户禁用它:

例子:

Defaults    requiretty
Defaults:your_username_goes_here !requiretty

关于linux - sudo 抱歉,你必须有 tty 才能运行 sudo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28202157/

相关文章:

linux - Virtualbox 上的 Ubuntu VM 不断中止

linux - 在linux中设置环境变量

linux - 加速/并行化大规模硬链接(hard link)循环

macos - -bash : gulp: command not found in Mac

linux - 如何在 shell 脚本中加入 2 个变量?

linux - Linux 内核中 wait_event 和 wake_up 之间的竞争条件

linux - 我应该使用哪个窗口管理器作为示例?

c++ - 是否可以在基于 Linux 的系统上使用 gcc 或 g++ 进行静态编译?

linux - 在 shell 中集成内置更新功能,以便在有可用时接收 OTA 更新

bash - bash 中前导零的范围