ssh remote command escape special characters when using variable

You should always enclose the command given to the ssh client for remote executing!

myuser@srv-local:~$ CMD="cat /etc/*release";ssh root@1.1.1.1 "$CMD"
Gentoo Base System release 2.0.3
myuser@srv-local:~$ CMD="cat /etc/*release";ssh root@1.1.1.1 $CMD
cat: /etc/lsb-release: No such file or directory
cat: /etc/os-release: No such file or directory
myuser@srv-remote:~$

You see the difference! The second line the special character “*” asteriks will be expanded by the shell locally and then the result will be send to the remote server for execution. In the second case the remote server will receive a command “cat /etc/lsb-release /etc/os-release” (because our local system has there two files) and not what you want “cat /etc/*release” on the remote.
We use variables above, because we want to point out

the problem, which often occurs when you use ssh remote command execution in a script.

Keep on reading!

Install openssh (sshd) server in Ubuntu 18.04 LTS

Yes, new major system upgrade new rules. If you’ve installed openssh server till Ubuntu 18 (Bionic Beaver) with just the simple command:

myuser@srv:~$ sudo apt-get install -y openssh-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package openssh-server is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'openssh-server' has no installation candidate
myuser@srv:~$

Now it is impossible as you can see. It is strange why they just did not include it as an alias just to prevent you from searching the Net (google?).

So there is a new way of installing OpenSSH server – it is a software collection called “OpenSSH server” and there is a new tool to manage such collections:

tasksel

So you must use tasksel to install OpenSSH server, here is the three command you should use:

sudo apt update
sudo apt install tasksel
sudo tasksel install openssh-server

And their explanation below in steps:

STEP 1) Update your server!

Because you could miss tasksel, it is not installed by default and even after clean install it seems not available before you do an update:

myuser@srv:~$ sudo apt update

STEP 2) Install tasksel

myuser@srv:~$ sudo apt install tasksel

STEP 3) Install OpenSSH server with tasksel

You are going to enter an console based graphic setup showing you the installation of the software collection “OpenSSH server”

myuser@srv:~$ sudo tasksel install openssh-server

Here is what is going to see after the above command:

main menu
tasksel installs openssh-sftp-server

main menu
tasksel installs openssh-server

* Throubleshooting – no tasksel packet!

Just DO NOT skip STEP 1) – update your package lists!!!

myuser@srv:~$ sudo apt install tasksel
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package tasksel

* All of the output