Sudo prevents the following command from executing - linux

I have been facing inconsistent behaviour between two versions of sudo for the following scenario:
$ sudo sleep 5
echo "hi" # during the 5 seconds
On one system, with sudo version 1.8.21p2, this buffers the second command and runs it afterwards -- but on a newer version (1.9.9), it doesn't:
$ sudo --version
Sudo version 1.9.9
...
$ sudo sleep 5
echo 'hi'
$
$ sudo --version
Sudo version 1.8.21p2
...
$ sudo sleep 5
echo 'hi'
$ echo 'hi'
hi
I found this bug which is relevant: https://bugzilla.sudo.ws/show_bug.cgi?id=786, however the discussion there suggests that this was fixed in version 1.8.20. Has it possibly been reintroduced between 1.8.20 and 1.9.9? If so, what could be a workaround?
Edit: to clarify, both of those were run after running a sudo command and providing the user password

In Ubuntu 22.04, the use_pty option is on in supplied /etc/sudoers file, which has this effect.

Related

"sudo: k0s: command not found": even though its script is executable and its location is in the path

What I am trying to do is:
To play with K0s. So, first I download the K0s scrips and make it executable:
$ curl -sSLf https://get.k0s.sh | sudo sh
.. and here is the terminal output:
> Downloading k0s from URL:
> https://github.com/k0sproject/k0s/releases/download/v1.20.6+k0s.0/k0s-v1.20.6+k0s.0-amd64
> k0s is now executable in /usr/local/bin`
At this point, when I type k0s in the terminal, I get the help page. Also, when I run type k0s, I get the /usr/local/bin/k0s
Again, when I run $ echo $PATH, I see that /usr/local/bin/ is included in the path variables.
The problem is:
When I try to run:
$ sudo k0s install controller --single
I get:
> sudo: k0s: command not found
But it works when I put the full path of the k0s:
$ sudo /usr/local/bin/k0s install controller --single
I tried this answer and this answer but both did not work. Both suggest changing the mode and erload the shell hash-table.
The question is:
what is the probelm, and how to fix it ?

How to copy bash commands from snippet without $ sign?

In most of the websites, I can see snippet with a bunch of bash commands ( With a Click to Copy Button), The problem with that button is this copy $ sign too.
Just like the image about, if I click copy, it will copy complete command INCLUDING $ Sign
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install gnome-shell
$ sudo apt-get install ubuntu-gnome-desktop
$ sudo apt-get install autocutsel
$ sudo apt-get install gnome-core
$ sudo apt-get install gnome-panel
$ sudo apt-get install gnome-themes-standard
We, programmers, are lazy in terms of doing this one by one, If I copy and paste this directly on bash it will show error since it will NOT recognize what is "$" as the command is starting with $ sign, is there a simple hack to let bash skip the first $ sign if command starts with it? If not any solution? I am tired of getting a response from the server and then pasting next commands
P.S This question is asked before I guess but that isn't EXACTLY what I have asked so moderators please understand my point.
Just cut it
while read -r line; do
$(echo "$line"|cut -d' ' -s -f2-)
done
After that, you'll just have to copy it to stdin(and end it witg Contr+D
As requested, here is a function that trims it:
function trimDollar(){
echo "$*"cut -d' ' -s -f2-
}

No manual entry for any command

I get the below response on trying to view manual for any command
No manual entry for <<command>>
On $ echo $MANPATH, It says
.:/usr/local/man:/usr/man
$ echo $PATH gives the following result
/usr/local/bin:/mis/TREE/bin:/usr/bin:/bin:/usr/ucb:/proj/blade/tools/bin
and on $MANPATH= man -w man it says
MANPATH=: Command not found.
What could be the issue? How to resolve this?
I am on Enterprise Linux 7 (Maipo).
if you have installed man-pages by
sudo yum install man-pages
, then do
sudo yum update

Windows Bash (WSL) - sudo: no tty present and no askpass program specified

After following this tutroial I get the following error when trying to run the commands as user or even sudo:
sudo: no tty present and no askpass program specified
The comments from Lurdan in this article state that you need to run
sudo -S <YOUR_COMMAND>
chmod 0666 /dev/tty
chmod doesn't work but sudo -S does, but surely there's another fix?
So silly, after looking further down I see a solution from Beorat:
To avoid the sudo tty issue and others, run these commands just before running do-release-upgrade:
sudo -S apt-mark hold sudo
sudo -S apt-mark hold procps
sudo -S apt-mark hold strace
If you've already upgraded, run the above commands, then manually downgrade to the Trusty packages:
sudo -S wget http://mirrors.kernel.org/ubuntu/pool/main/s/sudo/sudo_1.8.9p5-1ubuntu1.1_amd64.deb
sudo -S wget http://mirrors.kernel.org/ubuntu/pool/main/p/procps/procps_3.3.9-1ubuntu2_amd64.deb
sudo -S wget http://mirrors.kernel.org/ubuntu/pool/main/s/strace/strace_4.8-1ubuntu5_amd64.deb
sudo -S dpkg -i sudo_1.8.9p5-1ubuntu1.1_amd64.deb
sudo -S dpkg -i procps_3.3.9-1ubuntu2_amd64.deb
sudo -S dpkg -i strace_4.8-1ubuntu5_amd64.deb
More info here: https://github.com/Microsoft/BashOnWindows/issues/482
WSL uses the lxrun executable for management from Windows:
lxrun -h
Usage:
/install - Installs the subsystem
Optional arguments:
/y - Do not prompt user to accept
/uninstall - Uninstalls the subsystem
Optional arguments:
/full - Perform a full uninstall
/y - Do not prompt user to accept
/setdefaultuser - Configures the subsystem user that bash will be launched as. If the user does not exist it will be created.
Optional arguments:
username - Supply the username
/y - If username is supplied, do not prompt to create a password
/update - Updates the subsystem's package index
Given that, you can use lxrun /setdefaultuser root. Just thought I'd point out this side of it since it was required when I ran into the same issue as you after trying to upgrade to Xenial. I can confirm that running this command, then the wget / dpkg commands my issues were resolved.
The commands I used:
wget http://mirrors.kernel.org/ubuntu/pool/main/s/sudo/sudo_1.8.9p5-1ubuntu1.4_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/p/procps/procps_3.3.9-1ubuntu2_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/s/strace/strace_4.8-1ubuntu5_amd64.deb
dpkg -i sudo_1.8.9p5-1ubuntu1.4_amd64.deb
dpkg -i procps_3.3.9-1ubuntu2_amd64.deb
dpkg -i strace_4.8-1ubuntu5_amd64.deb
Finally, you might need to run sudo apt-get install -f in case you get The following packages have unmet dependencies [xxx] but it is not going to be installed
I got rid of the error by moving /etc/hosts to /etc/hosts.bu. After closing the shell en opening again, /etc/hosts is recreated and your computer name is added. The error is gone (for me.)

bash execute code stopped after execute ' sudo -i'

# !/bin/bash
sudo -i
cd /etc/apt/sources.list.d
echo "deb http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse" >ia32-libs-precise.list
sudo apt-get update
sudo apt-get install ia32-libs
sudo rm /etc/apt/sources.list.d/ia32-libs-raring.list
sudo apt-get update
when I execute this script ,it just do 'sudo -i ' then stop, who can help me ?
The sudo manpage says :
-i,--login
Run the shell specified by the target user's password data‐base entry as a login shell.
.
.
.
If no command is specified, an interactive shell is executed.
No wonder the execution of your script stops.
The commands
cd /etc/apt/sources.list.d
.
.
sudo apt-get update
are never reached because you have just spawned a new shell with sudo -i.
As [ #mona_sax ] suggested in comment,running a script as sudo may not be a good idea in the security context. It's not clear what your actual intention is, but if the intention is to run the script in background then remove sudo -i line and do :
./script 2>&1 1>/dev/null &
Because you don't specify a command to run as root, sudo invokes an interactive shell. It won't terminate until you exit from it (or it is killed by a signal, etc).
If you need it to return immediately, you could pass true as the command:
sudo true
However, in your case, it's probably better, given what you're doing, to just limit the script to only superusers:
#!/bin/sh
set -e
# check we are running as root
if [ $(id -u) != "0" ]; then
echo "ERROR: this script must be run as a superuser" >&2
exit 1
fi
Then it is up to the user to gain appropriate privileges, rather than encoding that into the script.

Resources