Connect to wireless network from command line, for wicd

In my personal life, I’m endeavoring to use less and less systemd and its derivatives and relatives and any other *ives (and I’m not even being figurative!).

So, for my devuan installs on my laptop fleet, I’m trying to automate all my installs and configs, because I automate things for work. And part of my documented workflow is to “Add to the wicd interface settings screen device ‘wlan0’ for the wireless nic.” So I wanted to learn how to connect to my wireless network from the command line.

After some research, I discovered a brief way to do it. I hope this helps somebody.

nid="$( wicd-cli -ySl | awk -v "n=${MYNETWORK}" '$NF==n {print $1}' )"
wicd-cli -y -n"${nid}" -p apsk -s "${MYPASSPHRASE}"
wicd-cli -y -n"${nid}" -c

I will explain a few parts briefly, but for more details you should check out the references below.
-y use wireless connection.
-S scan
-l list cached results, so what we just learned from the scan
-n use this network id, which is a number internal to wicd to keep track of the networks it has seen.
-p display a property
-s value, so with a -p SOMETHING and -s VALUE combo, it will set the property for you instead of display it.
-c connect.

In my tests, I discovered that I was unable to implement the saved password with the connect command. So it takes multiple invocations of wicd-cli, but I can live with that.
This for some reason took me way less time to research how to connect with wicd, than with nmcli in the past.



  1. Helped me minimally Wicd tutorial []
  2. what enlightened me about -p SOMETHING -s VALUE as opposed to -s ‘SOMETHING=VALUE’ like I tried at first README.cli []
  3. how I found wicd-cli in the first place: Linux: Can I get the wicd daemon to disconnect my wireless network from the command line? []

Web searches used

  1. wicd-cli connect example [google]
  2. wicd set wireless network from command line

man pages

  1. wicd-cli(8)
  2. wicd(1)

Alternatives and other reading

  1. How to connect and disconnect to a network manually in terminal? []

Instructions for Setting Up a CentOS 7 System with Bridged Networking for Virtual Machines

CentOS 7 bridging network card for virtual machines

My goal is to set up virtualization where the guests can access the entire LAN as well as the host over the network. The host should also be able to reach all the guests via the network.

This task was so simple, but somehow it eluded me for over a year. I use this document to establish a new kvm host in my network pool.

Install virtualization tools

sudo yum -y install libvirt qemu-kvm virt-install
sudo systemctl enable libvirtd.service ; sudo systemctl start libvirtd.service
sudo setsebool -P virt_use_nfs 1

Adjust the ethernet configuration

sudo su -
this_nic="$( nmcli device show | awk '/^GENERAL.DEVICE:/ && $2 ~ /e.*/ {print $2}' )"
this_nic_count="$( printf "%s\n" "${this_nic}" | sed '/^\s*$/d' | wc -l )"
if test ${this_nic_count} -ne 1 ;
   echo "Other than 1 nic detected. Please deal with manually. Aborted."
   # prepare values for bridge definition
   this_mac="$( ip -o link | grep "${this_nic}" | grep -oE 'ether [a-fA-F0-9:]{17}' | awk '{print $2}' | tr '[[:lower:]]' '[[:upper:]]' )"
   this_ipaddr="$( ip -o address show "${this_nic}" | grep -oE 'inet [0-9\.]{7,15}' | awk '{print $2}' )"
   # define bridge interface
      echo "DEVICE=${this_bridge}"
      echo "TYPE=Bridge"
      echo "ONBOOT=yes"
      echo "DELAY=0"
      grep -h -E 'DNS1|DNS2|DOMAIN|IPADDR|PREFIX|BOOTPROTO|GATEWAY|DEFROUTE' "${indir}/ifcfg-${this_nic}"
   } > "${indir}/ifcfg-${this_bridge}"
   # define ethernet card
      echo "DEVICE=${this_nic}"
      echo "HWADDR=${this_mac}"
      echo "ONBOOT=yes"
      echo "BRIDGE=${this_bridge}"
      grep -h -E 'UUID' "${old_nic_file}"
   } > "${temp_nic_file}"
   chmod --reference "${old_nic_file}" "${temp_nic_file}"
   /bin/mv -f "${temp_nic_file}" "${old_nic_file}"

systemctl restart network.service NetworkManager.service

Using the virtual host

With the setup complete, the environment is ready to serve virtual machines!

Install a virtual machine

vm=c7-03a ; time sudo virt-install -n "${vm}" --memory 2048 --vcpus=1 --os-variant=centos7.0 --accelerate -v --disk path=/var/lib/libvirt/images/"${vm}".qcow2,size=20 -l /mnt/public/Support/SetupsBig/Linux/CentOS-7-x86_64-Minimal-1804.iso --initrd-inject=/mnt/public/Support/Platforms/CentOS7/centos7-ks.cfg --extra-args "ks=file:/centos7-ks.cfg SERVERNAME=${vm}" --debug --network type=bridge,source=br0 --noautoconsole

Delete a virtual machine

vm=c7-03a; sudo virsh destroy "${vm}"; sudo virsh undefine --remove-all-storage "${vm}";




Internal files

  1. file:///mnt/public/Support/Platforms/CentOS7/centos7-ks.cfg

List current xvnc sessions in xrdp so you can reconnect to your old one


{ echo "user pid Xdisplay port"; { ps -ef | awk '/Xvnc :[[:digit:]]+/ {print $1,$2,$9}' | while read tu tpid tvnc; do sudo netstat -tlpn | awk -v "tpid=${tpid}" '$0 ~ tpid {print $4;}' | sed -r -e 's/^.*://;' -e "s/^/${tu} ${tpid} ${tvnc} /;" ; done ; } | sort -k3 ; } | column -c4 -t

The story

I connected to a gnome session on a terminal server, and disconnected. I wanted to reconnect to my current session, but apparently I got a new X session. After some research, I learned you can configure xrdp to prompt for the port number so you can get back to the previous session. However, then you have to know what to type in. After doing a manual ps and netstat, I found some useful numbers. What I needed to enter was the tcp port number, so 5919.

The explanation

You can have an entry in the /etc/xrdp/xrdp.ini file like the following block.


When you connect over RDP, select the “Reconnect” module and type in a port number, which you can find from the output of the oneliner.

{ echo "user pid Xdisplay port"; { ps -ef | awk '/Xvnc :[[:digit:]]+/ {print $1,$2,$9}' | while read tu tpid tvnc; do sudo netstat -tlpn | awk -v "tpid=${tpid}" '$0 ~ tpid {print $4;}' | sed -r -e 's/^.*://;' -e "s/^/${tu} ${tpid} ${tvnc} /;" ; done ; } | sort -k3 ; } | column -c4 -t
user       pid    Xdisplay  port
mjohnso    11448  :17       5917
mjohnso    12939  :18       5918
bgstack15  1219   :19       5919




Check if network port is open

On the local system, check if something is listening to the port:

netstat -tlpn

On a remote system, you can use telnet or ncat to check to see if you can actually get to the port:

echo '' | telnet myserver 1054

If successful, telnet returns ‘Connected to myserver’ before closing out.

echo '' | nc -v myserver 1054
$ echo '' | nc -v myserver 1054
Ncat: Version 6.40 ( )
Ncat: Connected to
$ echo '' | nc -v myserver 1055
Ncat: Version 6.40 ( )
Ncat: No route to host.