I have script that opens several terminal windows running iftop
for observing various ports activities.
Each terminal that opens asks me for the sudo password … which is a bit of a pain considering that there are 5 terminals overall.
So my question is, how do I type in sudo password once and have all the windows run using that permission rather than typing it in per window?
#!/bin/bash
TITLE="${USER}@${HOSTNAME}"' iftop (h=help, L=lin/log scales, t=line display mode, T=line totals, p=port display)'
gnome-terminal --title "$TITLE" -e 'sh -c "sudo iftop -P -f \"port 22\""' --hide-menubar --zoom=0.85
TITLE="${USER}@${HOSTNAME}"' iftop (h=help, L=lin/log scales, t=line display mode, T=line totals, p=port display)'
gnome-terminal --title "$TITLE" -e 'sh -c "sudo iftop -P -f \"port 33 or port 44\""' --hide-menubar --zoom=0.85
TITLE="${USER}@${HOSTNAME}"' iftop (h=help, L=lin/log scales, t=line display mode, T=line totals, p=port display)'
gnome-terminal --title "$TITLE" -e 'sh -c "sudo iftop -P -f \"(port 55) or (port 66)\""' --hide-menubar --zoom=0.85
I did try running the entire script as sudo
and that results in all the terminals being opened also being a sudo terminal. What I need is a regular terminal running the sudo iftop
instead.
Best Answer
Is
timestamp_type
in/etc/sudoers
or/etc/sudoers.d/*
set totty
orppid
?tty
is the default according tosudo
's man page:If it is set to
tty
orppid
, then that explains why you're being asked for a password every time. Eachsudo
command you're running is being executed in a separategnome-terminal
, and thus a separate tty AND a different parent PID.Looks like
global
is the only setting that will allow what you want.If that doesn't help, what's your
timestamp_timeout
setting? Is it set to0
? The default should be 15 minutes.Also check the other
timestamp*
settings (timestampdir
,timestampowner
). They could cause this problem iftimestampdir
(the default on my debian sid system is /run/sudo/ts) doesn't exist or is not rwX bytimestampowner
(default root).sudo
will log a descriptive error message via syslog and email the administrator (root) if these settings result in an error.One other option is to edit
/etc/sudoers
so that your user can runiftop
without needing to enter your password. e.g.See How to run a specific program as root without a password prompt? for more details on this.