Quote:
Originally Posted by jodumont
thanks for your quick answer but none of these works
I use Ubuntu 18.04LTS
@syg00
your suggestion only works if the line is commented such as '#Port 22' and don't work with 'Port 22'
sed -i 's|[#^]Port .*|Port 55555|g' /etc/ssh/sshd_config
|
Yes, because [#^] means: a character that is # or ^
Certainly the following was meant:
Code:
sed -i -E 's|(#|^)Port .*|Port 55555|' /etc/ssh/sshd_config
Normally it requires ERE ( -E or -r option).
With GNU sed extensions the following might work as well:
Code:
sed -i 's|\(#\|^\)Port .*|Port 55555|' /etc/ssh/sshd_config
Now it means: a leading # or at the beginning of the line.
The # somewhere can maybe sharpened by require it to be at the beginning of the line. Then it is
Code:
sed -i -E 's|(^#|^)Port .*|Port 55555|' /etc/ssh/sshd_config
or better, at the beginning of the line an optional #
Code:
sed -i -E 's|^#?Port .*|Port 55555|' /etc/ssh/sshd_config
as was given before by Turbocapitalist.