Skip to content

Commit 516f729

Browse files
committed
If sudo is run without a tty via ssh, suggest using "ssh -t"
The current warning message mentions using sudo's -S option but this will cause the password to be echoed without a terminal. In most cases, the user just needs to run ssh with the -t option.
1 parent 4dbb07c commit 516f729

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

docs/sudo.man.in

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.\"
33
.\" SPDX-License-Identifier: ISC
44
.\"
5-
.\" Copyright (c) 1994-1996, 1998-2005, 2007-2023
5+
.\" Copyright (c) 1994-1996, 1998-2005, 2007-2024
66
.\" Todd C. Miller <[email protected]>
77
.\"
88
.\" Permission to use, copy, modify, and distribute this software for any
@@ -25,7 +25,7 @@
2525
.nr BA @BAMAN@
2626
.nr LC @LCMAN@
2727
.nr PS @PSMAN@
28-
.TH "SUDO" "@mansectsu@" "August 9, 2023" "Sudo @PACKAGE_VERSION@" "System Manager's Manual"
28+
.TH "SUDO" "@mansectsu@" "December 20, 2024" "Sudo @PACKAGE_VERSION@" "System Manager's Manual"
2929
.nh
3030
.if n .ad l
3131
.SH "NAME"
@@ -1594,14 +1594,23 @@ option is specified) and the standard input has been redirected from
15941594
\fBsudo\fR
15951595
needs to read the password but there is no mechanism available for it
15961596
to do so.
1597-
A terminal is not present to read the password from,
1598-
\fBsudo\fR
1599-
has not been configured to read from the standard input,
1600-
the
1597+
Remote commands run via
1598+
ssh(1)
1599+
do not have a terminal available by default; passing the
1600+
\fB\-t\fR
1601+
option to
1602+
ssh(1)
1603+
will cause it to allocate a terminal which should allow
1604+
\fBsudo\fR
1605+
to read the password.
1606+
To allow
1607+
\fBsudo\fR
1608+
to run local commands without a terminal, the
16011609
\fB\-S\fR
1602-
option was not used, and no askpass helper has been specified either via the
1610+
option can be used to read a password from the standard input, or
1611+
an askpass helper can be configured via either the
16031612
sudo.conf(@mansectform@)
1604-
file or the
1613+
file or by setting the
16051614
\fRSUDO_ASKPASS\fR
16061615
environment variable.
16071616
.TP 6n

docs/sudo.mdoc.in

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\"
22
.\" SPDX-License-Identifier: ISC
33
.\"
4-
.\" Copyright (c) 1994-1996, 1998-2005, 2007-2023
4+
.\" Copyright (c) 1994-1996, 1998-2005, 2007-2024
55
.\" Todd C. Miller <[email protected]>
66
.\"
77
.\" Permission to use, copy, modify, and distribute this software for any
@@ -24,7 +24,7 @@
2424
.nr BA @BAMAN@
2525
.nr LC @LCMAN@
2626
.nr PS @PSMAN@
27-
.Dd August 9, 2023
27+
.Dd December 20, 2024
2828
.Dt SUDO @mansectsu@
2929
.Os Sudo @PACKAGE_VERSION@
3030
.Sh NAME
@@ -1492,14 +1492,23 @@ option is specified) and the standard input has been redirected from
14921492
.Nm
14931493
needs to read the password but there is no mechanism available for it
14941494
to do so.
1495-
A terminal is not present to read the password from,
1496-
.Nm
1497-
has not been configured to read from the standard input,
1498-
the
1495+
Remote commands run via
1496+
.Xr ssh 1
1497+
do not have a terminal available by default; passing the
1498+
.Fl t
1499+
option to
1500+
.Xr ssh 1
1501+
will cause it to allocate a terminal which should allow
1502+
.Nm
1503+
to read the password.
1504+
To allow
1505+
.Nm
1506+
to run local commands without a terminal, the
14991507
.Fl S
1500-
option was not used, and no askpass helper has been specified either via the
1508+
option can be used to read a password from the standard input, or
1509+
an askpass helper can be configured via either the
15011510
.Xr sudo.conf @mansectform@
1502-
file or the
1511+
file or by setting the
15031512
.Ev SUDO_ASKPASS
15041513
environment variable.
15051514
.It Li no writable temporary directory found

src/tgetpass.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,13 @@ tgetpass(const char *prompt, int timeout, unsigned int flags,
137137
ttyfd = open(_PATH_TTY, O_RDWR);
138138
if (ttyfd == -1 && !ISSET(flags, TGP_ECHO|TGP_NOECHO_TRY)) {
139139
if (askpass == NULL || getenv_unhooked("DISPLAY") == NULL) {
140-
sudo_warnx("%s",
141-
U_("a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper"));
140+
if (getenv_unhooked("SSH_CONNECTION") != NULL && getenv_unhooked("SSH_TTY") == NULL) {
141+
sudo_warnx("%s",
142+
U_("a terminal is required to read the password; either use ssh's -t option or configure an askpass helper"));
143+
} else {
144+
sudo_warnx("%s",
145+
U_("a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper"));
146+
}
142147
debug_return_str(NULL);
143148
}
144149
SET(flags, TGP_ASKPASS);

0 commit comments

Comments
 (0)