2

I just installed Ubuntu Server 22.04 and SSHed in. I'm not able to paste multiple sudo commands as I could with Ubuntu Server 20.04. This feels to me like a security feature that I don't want.

Previously (before 22.04) I could manually enter sudo -v and then paste some sudo commands and I'd get:

user@host:~$ sudo -v
[sudo] password for user:
user@host:~$ sudo mkdir test
user@host:~$ sudo rm -r test
user@host:~$ ls
user@host:~$

Now, with 22.04, I get:

user@host:~$ sudo -v
[sudo] password for user:
user@host:~$ sudo mkdir test
sudo rm -r test
user@host:~$ ls
test

How can I change this behavior?

Edit:

After trying what's suggested in this answer, I still get the same results. I did try pasting a second time after doing bind 'set enable-bracketed-paste off'.

user@host:~$ sudo -v
user@host:~$ bind 'set enable-bracketed-paste off'
user@host:~$ bind -v | grep bracketed
set enable-bracketed-paste off
user@host:~$ sudo -v
user@host:~$ sudo mkdir test
sudo rm -r test
user@host:~$ ls
test
user@host:~$

Edit 2:

I also ran xterm via ssh and X forwarding from my Mac and got the same results as a regular ssh connection.

aswine
  • 217
  • 2
  • 12
  • If you want to use **multiple** commands via `sudo`, why not use `sudo -i` and then just enter the commands into root shell without prefixing them with `sudo`? Why do you want to prefix each command separately with `sudo`? – raj May 09 '22 at 16:32
  • 2
    Does this answer your question? [Pasted text in Gnome Terminal in 21.04 is always highlighted](https://askubuntu.com/questions/1334205/pasted-text-in-gnome-terminal-in-21-04-is-always-highlighted) – vanadium May 09 '22 at 16:36
  • you just never got a prompt after the first sudo command – Esther May 09 '22 at 16:40
  • @raj, there are times when I want to paste multiple commands, some have `sudo` and some don't. – aswine May 09 '22 at 17:25
  • @vanadium, no I don't see the relevance of that question. Am I missing something? – aswine May 09 '22 at 17:27
  • 3
    @raj because it is **best practice** to use sudo only when you need to run a command that actually needs the privileges. Elevating the whole shell to the root user is not good practice and increases the surface area for very costly mistakes. – Nmath May 09 '22 at 18:05
  • @Nmath But I see no difference from safety point of view between `sudo X; sudo Y; sudo Z` and `X; Y; Z` typed in a root shell. – raj May 09 '22 at 18:20
  • 1
    In that answer, it is indicated to change the paste behavior back to how it previously was. – vanadium May 09 '22 at 19:39
  • @vanadium, I edited my question, showing that didn't work. – aswine May 09 '22 at 20:17
  • OK, I see. I cannot reproduce that issue on the desktop. Perhaps this is related to doing this over ssh. I retracted by close vote. – vanadium May 10 '22 at 07:57

2 Answers2

1

It's due to the addition of Defaults use_pty in /etc/sudoers, comment out the line to revert to the previous behaviour.

sudo
  • 11
  • 1
  • This saved me. How is this not upvoted 100 times? Isn't Ubuntu the most popular Linux distribution in the world? How can hundreds if not thousands of people be impacted by this? Thank you. – Dan Nissenbaum Jan 05 '23 at 05:19
0

Why not trying with

user@host:~$ sudo bash

and then write all your commands?