Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sudo on a computer using ssh inside a bash script

Tags:

bash

ssh

sudo

I'm trying to run a bash script that has:

ssh -l <username> <compname> 'sudo yum -y install expect'

I get the error:

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

on some computers but on others the process runs smooth. How can I prevent this?

like image 724
Guy Avatar asked Oct 31 '09 10:10

Guy


1 Answers

Use the -t flag to force a tty to be allocated:

ssh -t -l <username> <compname> 'sudo yum -y install expect'
like image 176
dave4420 Avatar answered Nov 13 '22 07:11

dave4420