by gosub100 · 1y ago · 0 comments
I'm an SRE for a service everyone has heard of. I have inadvertently pasted into my terminal prompt multiple times now, which has attempted to run each line as a command. I see there is a way to disable this at the shell for each client, but what about at the server level? This way I could enforce it as a policy, and not have to protect every single user (including myself) individually. Said differently, I want to keep everyone who ssh into a prod machine from being able to paste and execute multiple lines. But not forbid paste entirely.
The only thing I could think of would be to recompile bash and detect if the input was from a tty. If so, require at least 200ms between commands, and error out if the threshold exceeded. This would still allow the first pasted command to run, however.
It inserts a control sequence before and after the pasted contents that makes bash not execute all the lines. Instead it will keep them in the command line, post which you can choose to execute all of them in one go with enter or cancel with ctrl C.
bind 'set enable-bracketed-paste on'Imagine you want to run, say, Firefox like that (say because you'd like to see stdin/stderr output of what's going on without having to find to which log file it's outputting stuff: it's really just a silly example):
xterm> firefox
<-- the xterm is now "stuck here" (until Firefox exists)
if you now write, into that "blocked" xterm, the things you write shall execute when you exit/kill Firefox: Hello, world!
But one thing I used to do all the time and still occasionally do, first do this: xterm> firefox
<-- the xterm is now "stuck" here (until Firefox exits)
cat > /dev/null
You can now use that xterm as a temp paste buffer.So, yup, a good old cat > /dev/null works wonder.
so whatever you do, it should be a feature, even defaulted on. but never a policy that you enforce to "everyone who ssh into a prod machine"
if you find something that works well for you, add it as a suggestion to your developer docs.