VPN and Samba on Linux — easier than I expected

I have the server.ovpn file that OpenVPN GUI reads in and uses on Windows. I’d like to use a Linux client. I am running Debian.

First, we use NetworkManager (installed by default unless you did a minimal, customised installation). I install network-manager-openvpn, openvpn, resolvconf, network-manager-openvpn-gnome (though I am using the MATE desktop), samba and cifs-utils and remmina and its RDP plug-in, and for good measure openvpn-systemd-resolved — not 100% sure I need them all (and some are not relevant for this specific post), but …

$ sudo systemctl restart networkmanager

(This makes sure NetworkManager knows all these new toys have been installed.) I used openvpn from the command line to make sure I could make a connection:

$ sudo openvpn --config path/to/server.ovpn

and I could see machines on the VPN (for example, I could ping the server), so that was good. I knew it could work.

Then, went to NetworkManager in the MATE status bar and asked for a new VPN connection, OpenVPN compatible, using a saved configuration, and browsed to my ovpn file. Accepted all defaults and saved the connection, then chose it; was pleasantly surprised when it worked immediately.

Now, to mount the file shares. Ran caja (nautilus if you use gnome) and File > Connect to server > Chose Windows Share as the type, then put the server name (well, IP4 address, but a name would probably have worked as well or better) in the server box. Put the folder in the folder box (with leading /), domain (workgroup in Windows lingo) in its box, then username and password. Checked ‘make a shortcut’ and gave it a name; that also worked out of the box (files showed up in caja), so most of the functionality is there.

A few tips.

  • If you ever have to log into a Windows desktop or other account with something like “COMPANY\username” then COMPANY might work as a domain in the caja connection.
  • Don’t enter the folder and server like \\server\folder like you would in Windows — put server in one box and folder in the other.
  • Using an explicit IP4 address (123.234.345.345) might work but the server hostname is generally to be preferred; but I find that sometimes one works, sometimes the other, so you can try both. Server IP addresses are usually pretty stable — unlikely to be allocated by DHCP!
  • Most ovpn files contain the options needed in the top section. In my case, this meant that I did not do any config changes, just accepted what the saved config imported into NetworkManager. Maybe I was lucky …?
  • Where you would find the mounted folders in the Linux file system can be tricky. Some advice says ~/.gvfs, some ~/.cache/gvfs, some put the files in the /run tree. Given that we have not used superuser to do any of this, I’d expect the files to be in your personal file space, but YMMV. You might have to hunt around for the mount point.

Once you have the VPN working, you may be able to use RDP to work on a remote computer, as well as access files as I have done here.

Does not need sudo or root or superuser or whatever you want to call it.

crgrep in 2022 — search for text in any file! (Windows) including Word, Excel and PDF

crgrep is a very useful utility that can be used to search through directories full of Word files, Excel files, PDFs and so on.

It is a little bit manual to install, but actually very easy, and ell worthwhile once it is working. Regrettably, it is not maintained.

Download from https://sourceforge.net/projects/crgrep/

Extract the folder to (in my case) c:\users\username\installs, so now I have a folder called

C:\Users\username\installs\crgrep-1.0.5

Read the bloody instructions in the install instructions file:

C:\Users\username\installs\crgrep-1.0.5\INSTALL.txt

Add bin folder to path; to do this, type ‘env’ in Windows search box, then choose Edit environment variables for your account then select Path, click Edit and then New then put “C:\Users\username\installs\crgrep-1.0.5\bin” in a new line and say ok.

Now I need to find Java. I have ImageJ installed. crgrep specifies Java 8 (jdk1.8.0_xx). I have installed ImageJ using the file ImageJ bundled with 64-bit Java 1.8.0_172, and I put it in my local installs directory, so I have the java.exe file in:

C:\Users\username\installs\ImageJ\jre\bin

I can run it to see what the version is:

C:\Users\username\installs\ImageJ\jre\bin>java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)

Looks perfect!

Add this to the environment —  a bit like editing the path (above), but create a new environment variable:

JAVA_HOME=C:\Users\goossens\installs\ImageJ\jre

Do some tests

c:\> crgrep -help

OK, now for example, I want to search for ‘Fred Smith’ in all DOCX files in a tree of files starting at the current directory. I only want to look in files that have ‘final’ in the title, and I want to find occurrences that have a single character between Fred and Smith, but it may not be a space.

c:\etc\etc\etc> crgrep -r --colour=always "Fred?Smith" "**\*final*.docx"

What’s going on?

crgrep — the command

-r — recursively search subdirectories

–colour=always — turn occurrences of the desired pattern red in the output

“Fred?Smith” — the search pattern; ? means any one character, so this will find ‘Fred Smith’, ‘Fred-Smith’, ‘FredQSmith’ and so on. Note it is enclosed in quotes

“**\*final*.docx” — the pattern for the files to look in; ** means ‘dig through all subdirectories’, and *final*.docx means find all files that have file names of the form <some text>final< some text>.docx. Note it is enclosed in quotes

Works a treat.

OpenVPN and caja and Samba

Note to self.

In an X term, start OpenVPN:

$ sudo openvpn --config /home/username/path/to/configfile.ovpn

Once it connects, Ctrl+Z and then:

$ caja  smb://192.168.123.56/folder

For some reason, double-clicking on folders does not work, but right-click and choosing Open does.

Can then navigate to wherever is needed and copy files back and forth as if local.

If using the text client, after Ctrl+Z:

smbclient --socket-options='TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF=131072 SO_SNDBUF=131072' -t 60 \\\\192.168.123.56\\folder -U remoteusername

Then once in, issue:

iosize 16384

These settings seem to help with transferring big files. The extra control over the connection relative to the caja connection can prove useful and more stable when your network is flaky.

I’m beating out a samba