A terminal line wrap split a chmod command
The pasted command broke at chmod 600, and the key was still added.
I needed to add my workstation’s public key to two new hosts. I pasted a long one-liner from my laptop: make ~/.ssh, append the key to authorized_keys, then chmod 600 the file.
The terminal wrapped the line right after chmod 600, and the paste carried a real newline into the command. The output was:
chmod: missing operand after '600'bash: line 2: /root/.ssh/authorized_keys: Permission deniedIt looked like a failure, but most of it had worked. The commands are chained with &&, so mkdir and the echo ... >> authorized_keys had already run before chmod failed. Line 2 was just the file path, and the shell tried to run it as a command.
The file permissions were already acceptable to sshd, so the workstation could log in to both hosts right away. Then it ran the chmod 600 cleanly over SSH.
From now on I’ll keep pasted lines short, under about 70 characters, or use backslash line continuations. A soft wrap should never be able to split an argument.
Do you have a habit for pasting long commands safely?
Recipes written later from this work: