I found myself in a situation where I needed to connect (with ssh)
to a remote machine where there were no text editors installed
(no ed
, ex
, vi
or nano
).
This is on a running production server.
We don't install (and don't allow) text editors,
basically because of the beliefs:
- you don't really need them.
- leaving them out probably adds to security as well.
However, you still need to debug and troubleshoot from time to time.
The shell is Bash.
The only way that I can see to edit text files
is to use echo
and cat
.
Can you please share your experience
of how would you edit text files in such a situation?
Perhaps there is a way to pipe a file to local vim
?
Update: To clarify, the question is more just a theoretical case. A couple of times I had to debug pods in a k8 cluster with very minimal setup. So you may need to update some configs.
sed
andawk
. – Panki Aug 21 '20 at 10:13echo
andcat
? What do you mean by "editing" the file? I mean, there are plenty of text manipulation tools available on any Unix system, includingsed
,awk
etc. You also didn't mention whethered
was available or not. – Kusalananda Aug 21 '20 at 14:31echo
norcat
are editors. Is there an environmental restriction preventing editing on that system? Perhaps there's a good reason that editing is prohibited. Are you an administrator of that system? Someone who can install additional tools, such as editors? – Jeff Schaller Aug 21 '20 at 14:56echo
andcat
can't edit files without some other tool (typically a shell) opening those files onto their stdout. So presumably you also have a shell on that system. Which one would that be? – Stéphane Chazelas Aug 21 '20 at 15:02ed
, if you want to raise the bar to entry slightly. – Jeff Schaller Aug 27 '20 at 16:18