Linux – Bulk UnRAR

If you’re not familiar with RAR files, they are like ZIP files. RAR is an archive format.

I had a collection of more than 150 RAR files in a single folder I needed to unrar (that is, open and extract from the archive). Doing them one at a time via KDE’s Ark software would work, but it would have taken a long time. Why spend that much time when I could automate the process.

Enter a loop bash script in KDE’s Konsole:

for i in *.rar; do unrar x "$i"; done

Here’s how the command works. The “for i in” part starts the loop (note: you can use any letter here). The “*.rar” component indicates that we want the loop to run through all the RAR files in the directory, regardless of the name of the file. The “do” command tells the loop what command to run. The “unrar x “$i”” component tells the software to use the unrar function which unpacks the archive. The “x” in that command tells the software to use the directory structure inside the RAR archive. The final piece of the loop after the second semi-colon – “done” – indicates what the terminal should do once the loop completes.

It took about 20 minutes to run through all the RAR files, but I used that time to create this tutorial. Doing this by hand would have taken me hours.

 83 total views,  4 views today

Linux: Batch Convert .avi files to .mp4/.mkv

I’ve been trying to clean up my video library since building my latest NAS. In the process, I found a number of .avi files, which is an older file format that isn’t widely used these days. While every time a file is converted it loses some of its quality, I was willing to risk the slight quality reduction to convert the remaining few files I had to convert into more modern file formats.

I initially tried converting the files using HandBrake. But given the number I needed to convert, I decided pretty quickly that I needed a faster method for this. Enter stackoverflow.

Assuming you have all of your .avi video files in a single directory, navigate to that directory in a terminal and you can use the following single line of code to iterate through all of the .avi files and convert them to .mp4 files:

for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done

In case you’re interested, the code is a loop. The first part starts the loop (“for i in *.avi;”), telling the computer to look for every file with the file extension .avi. The second part tells the computer what to do with every file with that extension – convert it to a .mp4 file with the same name. The last piece indicates what to do when the loop is completed – done.

Of course, this code could also be used to convert any other file format into a different format by replacing the .avi or .mp4 file extensions in the appropriate places. For instance, to convert all the .avi files to .mkv, the code would look like this:

for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mkv"; done

Or if you wanted to convert a bunch of .mp4 files into .mkv files, you could do this:

for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mkv"; done

BONUS:

If you have .avi files in a number of subfolders, you’ll want to use this script:

find . -exec ffmpeg -i {} {}.mp4 \;

To use it, navigate in a terminal to the top-level folder, then execute this command. It will search through all the subfolders, find all the files in those subfolders, and convert them all to .mp4 files.

Of course, if you have a mixture of file types in the folders, you’ll want a variation of this command that searches for just the files of a certain type. To do that, use this command:

find . -name *.avi -exec ffmpeg -i {} {}.mp4 \;

This command will find all the files with the extension .avi and convert them all to .mp4 files using ffmpeg.

And, if you’re feeling particularly adventurous, you could search for multiple file types and convert them all:

find . -name *.avi -or -name *.mkv -exec ffmpeg -i {} {}.mp4 \;

This code would find every file with the extension .avi or .mkv and convert it to .mp4 using ffmpeg.

NOTE: This command uses the default conversion settings of ffmpeg. If you want more fine-tuned conversions, you can always check the options available in converting video files using ffmpeg.

 723 total views,  7 views today

Teaching with a Mask – Headset Solution on Linux

My university, the University of Tampa, is doing what it can to continue teaching in-person classes (many are hybrid) during the COVID-19 pandemic. To facilitate that, our IT folks installed webcams and microphones in all of our classrooms. Unfortunately, the classrooms all have Windows-based desktops that don’t include all the software I need for educating my students (e.g., LibreOffice, Zotero, RStudio, etc.). I have always just plugged my laptop into an HDMI cable and then projected directly from it.

However, now that I’m teaching in a mask that substantially muffles my voice, I need a microphone that is projected through the speakers in the classroom so the students in the back can hear me, particularly when the A/C is on. I tried using the microphone provided the first day of class and ended up having to hold it for the entire class and it still cut out regularly. Our IT folks suggested we could start a Zoom meeting on the desktop, connect our laptop to it, and then display our laptop in the Zoom meeting and project that onto the screen so we can use our laptop and a microphone. That seemed like a kludge approach to solve the problem.

I figured there had to be a better way. So, I did a little thinking and a little research and found one. The answer – a bluetooth headset designed for truckers! Yep, truckers to the rescue!

If I could get a bluetooth headset to connect to my computer and then project the sound through the classroom’s speakers via bluetooth, I could continue to use my laptop to teach my class while still having a microphone to project my mask-muffled voice. Admittedly, this required a couple of hours of testing and some trial and error, but I got it working. Now, I have my own microphone set up for the classroom (I bring it with me) and can continue to use my laptop instead of the Windows-based PC.

So, how did I do it?

First, get yourself a bluetooth headset. I bought the Mpow M5 from Amazon. This is the perfect style headset as it has just one earphone, meaning I can still hear perfectly fine when students are talking to me in the classroom.

Second, connect the headset to your laptop. I’m going to assume your laptop has built-in bluetooth. Mine, a Dell Latitude 7390, does. Pairing it with my laptop was super easy. (If you don’t have bluetooth built-in, there are cheap USB bluetooth dongles you can buy as well.)

Third, the Linux part. I installed the package “blueman,” which provides a GUI interface for working with bluetooth devices. I didn’t know if this would be necessary, but, it turns out, it definitely was. Once you have your headset connected, open the blueman GUI and you’ll see this:

The next part stymied me for a while. Initially, my computer detected the headset as just headphones and not a headset with a microphone. I didn’t know why. Eventually, I got lucky and right-clicked on the Mpow M5 device in blueman and got a context window with the option I needed:

When you right-click on the device, you can select “Audio Profile” and then “Headset Head Unit”. The default, for some reason, was “High Fidelity Playback.” Once I did that, Linux detected the microphone.

Before you continue, make sure you have plugged in the HDMI cable as you’ll need that connected for the next part.

Next up was making sure all my audio settings were correct. This, too, took some trial and error. The settings window you need is paudio or Pulse Audio, which goes by different names in various versions of Linux. Regardless, here’s what the window looks like:

I’ll go over the settings for each tab, though the first two – Playback and Recording – won’t have anything in them until you start up OBS Studio, which I’ll cover shortly.

In the Configuration tab, you should now see your Mpow M5 connected as a Headset and you should see Built-in Audio. This may not say “Digital Stereo (HDMI) Output” to begin with. There is a drop down menu there. Click on it and you’ll see various options:

The default is “Analog Stereo Duplex”. Click on that drop down and select the HDMI Output. (NOTE: I typically use just “Digital Stereo (HDMI) Output” without the “+ Analog Stereo Input”. I have the wrong one highlighted above, but it should still work.)

Here’s what the Input Devices tab should look like:

And here’s how the Output Devices tab should look:

You probably will need to change one thing on the Output Devices tab. Make the HDMI output the default (click the little blue icon). You may also need to mute the Mpow M5 on this screen. Either way, you want to make sure that the HDMI output is where the sound is going.

Now, we need another piece of software. (NOTE: For those using Windows or Mac who want to do this as well, here’s the software that you’ll use that should use a fairly similar set up.) The software is OBS Studio, which is free and open-source software that works on all platforms. Install OBS Studio, then open it up.

The software is very good at detecting everything on your computer. Here are the settings I had to adjust. In the bottom right corner of the software, click on “Settings” and you’ll get a window with various tabs (tabs are on the right). The one you need is “Audio”. Click on that and you’ll see this:

In the Devices section, you’ll need to change the following: “Desktop Audio” should be set to “Built-in Audio Digital Stereo (HDMI)”. “Desktop Audio 2” should be disabled. “Mic/Auxiliary Audio” should be set to “Mpow M5.” All the others should be disabled. Then, under “Advanced,” where it says “Monitoring Device,” select “Monitor of Mpow M5.” Then click Apply or OK.

Close that window then click on “Edit” -> “Advanced Audio Properties” and you’ll get this window:

In that window, where you see “Audio Monitoring,” click on the drop down option for “Mic/Aux” and set it to “Monitor and Output.” What this does is tells the operating system that you want to monitor the audio from your Mpow M5 headset and output it through the speakers. Select “Close” and, assuming you’ve done everything correctly, you should now hear your voice coming out of the speakers. Woot!

A little more detail may be helpful, though. Back to Linux. If you return to the Pulse Audio window, you’ll now see that there is information in the remaining two tabs. Here’s what you should see in the Recording tab:

And here’s what you should see in the Playback tab:

And here is how I look with my headset and a mask:

Some notes:

I haven’t tested this with Zoom yet. I probably will to make sure that the audio also goes through Zoom.

OBS Studio can actually be used to record your presentation as well. It’s designed for streaming gamers, but works just as well for screen capture. So, if you need to record your class, just use OBS Studio to record your audio and your screen during the class.

 2,391 total views,  3 views today

Kubuntu – Audio CD Ripping

I mostly buy digital audio these days. My preferred source is bandcamp as they provide files in FLAC (Free Lossless Audio Codec). However, I ended up buying a CD recently (Last Night’s Fun by Scartaglen) as there wasn’t a digital download available and, in the process, I realized that there are lots of options for ripping the audio from a CD on Linux and quite the process to get the files ripped, tagged, properly named, and stored in my library. This is my attempt to summarize my process.

Format/Codec

First, you need to decide in what format you want the audio from the CD. As noted, I prefer FLAC these days. Given how relatively inexpensive storage is, I no longer need to scrimp on space for the most part. If space was an issue, ripping the files to mp3 format at, say, 192 kbps at a variable bit rate would probably be the optimum balance between decent quality and small size. But I prefer the best quality sound with no real regard for the size of the resulting files. It helps that I store all my music on a dedicated file server that runs Plex. That solves two problems: I have lots of space and Plex will transcode the files if I ever need that done (if, for example, I want to store the music on my phone and want it in a different format). So, my preferred file format is FLAC. (Another option is OGG, but I find not as many audio players work as well with OGG.)

There is another issue that I recently ran into: single audio files with cue sheets. Typically, people want their audio in individual files for each song. However, if you want to accurately represent an audio CD, the best approach to do this is to rip the audio as a single file with a corresponding cue sheet. The cue sheet keeps an exact record of the tracks from the CD. With the resulting two files, the audio CD can be recreated and burned back to a CD. I have no real intention of burning the audio back to a CD (I want everything digital so I can store it on my file server), but it’s good to know about this option. Typically, those who opt for this approach use one of two formats, .flac or .ape, for storing the audio and .cue for storing the timing of the tracks. The .ape format is a proprietary format, however, so it is definitely not my preferred approach.

As a quick illustration for how file format is related to size, I ripped my demonstration CD, Last Night’s Fun by Scartaglen into a single FLAC file and a single mp3 file (at 192 kbps using a variable bit rate) and put the resulting files into the same folder so you can see the size difference:

As you can see, the FLAC rip resulted in a file that was 222.9 MB compared to the mp3 file that is only 49.4 MB. The FLAC file is about 4.5 times the size of the mp3 file. A higher-quality mp3 rip at 320 kbps at a constant bit rate resulted in a 54.8 MB file. A pretty good estimate would be that the FLAC format is going to be somewhere between 3 to 5 times the size of an mp3 file. Thus, if space is an issue but you want good quality, ripping your music to the highest quality mp3 (320 kbps) is probably your best option. If space isn’t an issue and you care more about quality, FLAC is the way to go.

NOTE: I also ripped the disc to OGG and the file size was 38 MB.

Ripping Software

First, if you’re planning on ripping to FLAC on Linux, you’ll need to install FLAC. It is not installed in most distributions by default. This can be done easily from the terminal:

sudo apt-get install flac

Without FLAC installed, the software below won’t be able to rip to FLAC.

K3b

K3b is installed in Kubuntu 20.04 by default and is, IMO, a good interface for working with CDs and DVDs. When I inserted my demonstration CD into my drive, Kubuntu gave me the option of opening the disk in K3b. When I did, K3b automatically recognized the CD, grabbed the information from a CDDB, and immediately gave me options for ripping the CD:

When you click on “Start Ripping,” you get a new window:

In this new window, you have a bunch of options. You can change the format (Filetype). With the FLAC codec installed, the options listed are: WAVE, Ogg-Vorbis, MPEG1 Layer III (mp3), Mp3 (LAME), or Flac. You can obviously change the Target Folder as well. K3b also gives you the option of creating an m3u playlist and the option “Create single file” with “Write cue file” which is where you could create the single file and cue file from the CD as noted above. There are also options for changing the naming structure and, under the Advanced tab, options for how many times you want to retry reading the CD tracks. K3b is pretty fully featured and works for well for ripping audio CDs.

Clementine

My preferred music player in Linux is Clementine. I have used a number of music players over the years (e.g., Banshee, Rhythmbox, Amarok), but Clementine has the best combination of features while still being easy to use. Clementine is in the repositories and can easily be installed via synaptic or the terminal:

sudo apt-get install clementine

Clementine also has the ability to rip audio CDs. Once your CD is inserted, click on Tools -> Rip audio CD:

You’ll get this window, which is similar to the ripping window in K3b:

If the information is available in a CDDB, Clementine will pull that information in (as it did for my demonstration CD). You then have a bunch of options for the Audio format: FLAC, M4A, MP3, Ogg Flac, Ogg Opus, Ogg Speex, Ogg Vorbis, Wav, and Windows Media Audio. The settings for each of these can be adjusted in the “Options” box. One clear advantage of Clementine over K3b is that you can readily edit the titles of the tracks. Another advantage of Clementine over K3b is that you could import the files directly into your music library.

Ripping from a Cue Sheet

Another scenario I have run into on Linux is having a single file for the audio from a CD with a corresponding .cue sheet (the file is typically in the FLAC format, but I have also run into this in .ape format). I used to immediately turn to Flacon, a GUI that helped rip the single file into individual tracks. However, I have had mixed success with Flacon working lately (as of Kubuntu 20.04, I couldn’t get it to work). Never fear, of course, because Flacon is really just a GUI for tools that can be used in the terminal.

To split a single FLAC file with a corresponding .cue sheet into the individual tracks, you’ll need to install “shntool“:

sudo apt-get install shntool

(NOTE: It’s also a good idea to install the suggested packages, “cuetools,” “sox,” and “wavpack” but not required.) Assuming you have already installed “flac” as described above, ripping a single FLAC file into the individual tracks is fairly straightforward. The easiest way is to navigate to the folder where you have the FLAC file (e.g., “audiofile.flac”) and the cue sheet (e.g., “audiofile.cue”). Then use the following command at the terminal:

shnsplit -f audiofile.cue -o flac audiofile.flac 

Breaking the command down, “shnsplit” calls the program “shnsplit” which is part of the “shntool” package. The “-f” tells the program to show detailed format information. The first file is the cue sheet. The “-o” indicates that you are going to specify the output file format extension. After the “-o” is the target file format “flac” and the last file is the single FLAC file that you want to split.

Here’s a screenshot of me rippling the single FLAC file from my demonstration CD into individual FLAC files:

If you happen to run into a single audio file in the .ape format, shntool probably won’t be able to read it so the above command won’t work. However, a simple workaround is to convert the file to flac format using ffmpeg, which can read it. Here’s the command you could use from the terminal:

ffmpeg -i audiofile.ape audiofile.flac

That command will call ffmpeg (which you probably have installed) and convert the .ape file into a .flac file which can then be split using the command above (assuming you have a corresponding cue sheet).

Tagging Software

Let’s say I have successfully ripped my files into my desired format and now I want to tag them. There are a number of software packages that can do this, but my preferred software is Picard by MusicBrainz. Picard is open source, which is awesome, but it also interfaces with the MusicBrainz website and pulls in information that way, which means your files will get robust tagging information. If you pull in all the information from MusicBrainz, not only will the artist and album be tagged, but so to will lots of additional information, depending on how much was entered into the database by whoever added the album in the first place. (NOTE: Clementine also interfaced with MusicBrainz but this broke in 3.1. Once it broke, I started using Picard directly and now I realized that it has a lot more features than Clementine’s implementation, so I just use Picard. However, you could try doing this in Clementine as well.)

Again, I’ll use my demonstration CD to illustrate how this is done. I ripped the tracks into individual FLAC files above. Those tracks are completely devoid of tags – whatever software I use to try to play them won’t know what the audio files are. The screenshot below illustrates this. I used MediaInfo (a gui for pulling information from audio and video files in Linux) to pull available information from the file. It shows the format and length but provides no information about the artist or album, which it would if the file had tags.

We’ll use Picard to find the album and add all the tags. First, of course, install Picard:

sudo apt-get install picard

Open the program. Now, since my files have no tag information, I’m going to click on Add Files (you can also add a folder with subfolders, which then has Picard run through multiple audio files, a great feature if you are tagging multiple albums at the same time).

You’ll get a new window where you can select the audio files you want to add. Select them and then click “Open.”

If the files have existing tags, Picard will do its best to group the tracks together and may even associate the files with the corresponding albums. In my case, it simply puts the files into the “Unclustered” category:

Since I pulled them all in from the same folder, I can select the tracks and then click on the “Cluster” button in the toolbar and Picard will cluster the files.

Clustering is a first step toward find the corresponding album information. Once they are grouped together, they will show up in the Cluster category:

Without any tag information, Picard is unlikely to find the corresponding album if you select the cluster and then click on “Lookup.” If there was some tag information in the files, that might be enough for Picard to find the corresponding albums, so you could just select the album and then click on “Lookup.” In this case, that won’t work. So, I’m going to use a different approach. If you right-click on the cluster, you can select “Search for similar albums.”

This gives you a window where you can enter search terms to try to find the corresponding album in the Music Brainz database. Based on the limited information it has, it will try to find a corresponding album automatically. But it likely won’t find it because there are no tags, so there is virtually no information available. Generally, I have found that I have better luck finding albums if I use the album title first followed by the artist, like this “Last Night’s Fun Scartaglen” then hit enter:

Once you find the correct album, select it and then click on “Load into Picard” at the bottom of the window.

Once you do that, the album will move to the right side of the screen. If all of the tracks are included and Picard is able to align them with the corresponding information it has from the database, the CD icon will turn gold. If there is a little red dot on the CD, that means Picard has tag information that can be saved to the individual tracks.

Click on the album and then click the “Save” button in the toolbar and the tag information will be saved to the files.

You can track the progress as tracks will turn green once the information has been successfully added to the tags.

You can also set up Picard to modify the file names when it saves information to the files. Click on “Options” then click the checkmark next to “Rename Files.”

I typically let Clementine rename my files when I import them into my Music library, so I don’t worry about this with Picard, but it is a nice option. Finally, here’s that same Mediainfo box with the tagged file showing that information about the artist and track is now included in the file:

 2,282 total views,  6 views today

Linux – Video Tag Editing

Not everyone may be as particular as I am about having my files organized, but I like to make sure everything is where it’s supposed to be. I make sure my music is tagged accurately. I also like to have my video files tagged correctly. What does that mean? Just like with audio files, video container formats include as part of the file some tags that provide information about the file. Those tags can include the name of the video, the year, and other information (e.g., genre, performers, etc.). If you rip files or have digital copies, it’s not really necessary to update the information in the tags. However, depending on the software you use to play your video files, having that information included in the tags substantially increases the odds that your video player will be able to figure out what the video is and will then be able to retrieve any other relevant data. Thus, having accurate metadata in your video files is nice. It’s not necessary, but nice.

I was cleaning up some video files the other data and realized that I didn’t have accurate tags in some of them. I opened the video in VLC and then clicked on “Tools” -> “Media Information”:

I wanted to see the tags in the video file.

Here’s what VLC saw:

Yep, I’m working with Frozen!

As you can see, it didn’t have any tags filled except “Encoded by.” It actually filled the title by pulling the name of the video file itself. The minimum tags that should be included in a video file are: title and year, but including genre and some of the performers is always nice.

While there are a number of music file tag editors that work very well on Linux (e.g., Picard), I have struggled to find a good video metatag editor for Linux. I had one that was working for a while, Puddletag, which actually worked quite well even though it only billed itself as a tag editor for music files. However, Puddletag does not appear to be maintained anymore and, as of Kubuntu 20.04, it is no longer in Ubuntu’s repositories and the PPA does not contain the correct release file. I could try building it from source, but I wanted to see if there was a good alternative.

After googling around, I found one that seems to work quite well – Tag Editor. (You have to love the Linux community: call the software exactly what it does!) Here’s the GitHub site. And here’s where you can download an AppImage (I went with “tageditor-latest-x86_64.AppImage”), which worked great on Kubuntu 20.04.

Once you’ve downloaded the AppImage, you can set it to be executable (right-click and select “properties” then, on the “permissions” tab, select “executable”) or just double-click it and allow it to be executed. It should load.

In the left pane, navigate to your video file:

Once you find the file, you can see all of the tags that can be edited. Fill in the information:

Once you’ve filled in the tags you want to add or modify, click on “Save” at the bottom of the screen:

I particularly like this next feature. Once you click save, it shows the progress and actually tells you what stage it is at in saving the tags in the file:

Progress is in the circle with robust information on what it is doing next to it.

Tag Editor also does something that I actually questioned at first until it saved my bacon – it makes a backup of the file before it writes the new file. The backup file is named the same as the original file but with a new file extension: “.bak”.

You can see the backup copy of Frozen (“Frozen.m4v.bak”) just below the updated copy.

I initially thought this was just going to be annoying as I’d have to go through and delete all the backup copies once I was done. However, I did run into a couple of files that, for whatever reason, could not be modified. Partway through the tag saving process, I got an error message. Sure enough, Tag Editor, in writing the file, had stopped midway through. If a backup file wasn’t made, I would have lost the video. I don’t know exactly what caused the errors, but I quickly learned to appreciate this feature.

Just to illustrate that the tags were updated, I opened the new file in VLC and went back to the media information:

As you can see, the Title, Date, and Genre fields are now filled with accurate information.

Unlike, say, mp3 audio files, video files can take quite some time to update because the file has to be re-written. With a very fast computer, this won’t take an exorbitant amount of time. But it is a much lengthier process than updating tags in mp3 audio files.

 3,744 total views,  3 views today

Plex on Linux – Video Files Not Detected

I added a number of video files to my Plex server the other day and, when I checked Plex, some of them had not shown up in the corresponding library. I tried the obvious solutions. First, I selected the options for the library and then chose “Scan Library Files”:

That will often solve the problem, but it didn’t. Then I went for the bigger ask for my Plex server and selected “Manage Library -> Refresh all Metadata”:

That didn’t solve the problem either. Since my Plex server is on Linux, it took me a minute to think it through, but I wondered if the files I had put into the library had the appropriate permissions for Plex.

(Quick aside for those not used to Linux permissions. All files and folders on Linux have permissions assigned to them that dictate what can and cannot be done with them. Basically, it’s a 3×3 set of permissions. There are three options for what can be done with a file: Read, Write, Execute. Then there are three categories of those who can interface with the file: Owner, Group, Others. Thus, you can set the Owner to be able to Read, Write, and Execute a file while not allowing the Group or Others to do the same. Any combination of these permissions is theoretically possible.)

A quick check of the files on my Plex server showed that, indeed, some of the files had permissions settings that were likely interfering with Plex’s ability to index the files:

In the image above, you can see that the permissions for the two lower files (the first and second half of the Sevilla vs CFR Cluj game) are 600 with me as the owner and not “plex.”

My immediate response was to change the permissions to make them fully accessible to make sure that Plex could read them. To do that, I used the following command:

sudo chmod 777 -R /plexserver/videos/newfiles

Security gurus will freak out about this as I basically made those files accessible with no restrictions whatsoever. But, it did solve the problem with Plex. As soon as I changed the permissions, Plex was able to detect and index the files. However, that’s not best Linux security practice.

The general rule of thumb for Linux permissions is that you should grant sufficient permissions to do what you need but should never grant more lenient permissions than you need to. It turns out, Plex has a very nice article on Linux permissions. Based on that article, the command I should have used for those files was:

sudo chmod 644 -R /plexserver/videos/newfiles

Once I changed the permissions, my Plex server was able to find and index the file.

Technically, what I should probably do is make the user “plex” an owner of the files, which would then allow me to keep the permissions as restrictive as possible. That is done with the “chown” command. If I did that, I could simply give the plex user ownership and then leave the permissions such that the owner can read and write to the file (so, 600). Both of these options actually work, with the first being more permissive than the second. But, you can see with my files that I set one to 644 with me as the owner and another at 600 with plex as the owner:

And, in this screenshot, you can see that Plex was able to recognize them both and index them since it now has “read” permissions for the file:

So, what is the best approach here? If you’re lazy, you could set all the permissions to 777. That gives Plex (and everyone else) complete access to all your media files. If you want to be somewhat restrictive, you could set the permissions for media files in Plex to 644, which gives the owner read/write access and the plex user, if it is not an owner of the file, read access. If you want to be more secure, you could set the permissions to 600 and set the plex user as an owner of the file, which would restrict the permissions for the file to read/write for the owners and no access for everyone else.

 3,568 total views,  2 views today

Linux/Kubuntu – Disable Network Printer Auto Discovery

I don’t know when Kubuntu started automatically discovering printers on networks and then adding them to my list of printers, but it is a problematic feature in certain environments – like universities (where I work).

I set up my home printer on my laptop easy enough. But, whenever I open my laptop and connect to my work network, this feature searches for printers on the network and then adds them to my list of printers. I now have hundreds of printers that show up in my printers dialogue:

I didn’t manually add any of those printers. They were added automatically and are causing problems. First, it’s a pain in the ass to find the printer I want. Second, when I shutdown my computer, the OS has to run through all of those printers and make sure they are disconnected, which makes the OS hang for a couple of minutes every time I want to close down.

This is obviously a great idea in principle, but problematic in this environment.

So, how to turn this off. I found a solution. In a terminal, edit the following file:

sudo nano /etc/cups/cups-browsed.conf

In that file, you should just have to uncomment the following line (remove the hashtag ‘#’):

BrowseProtocols none

So, from this:

To this:

Afterward, try running the commands:

service cups-browsed restart
service cups restart

After making this change, my computer no longer automatically adds shared printers on my network. Hooray!

Unfortunately, making this edit did not remove all the shared printers it had already installed. I still had to remove them all manually, which was annoying. But at least they won’t be reinstalled automatically.

 2,667 total views

Linux – Failing to Read Encrypted DVDs

Thanks to the fine folks at VLC and Ubuntu, watching DVDs on Linux is generally pretty straightforward. Install “libdvd-pkg” and follow the prompts and you’re generally good to go. That works for me almost all of the time.

However, I recently tried to watch a DVD and had no luck. I would insert the DVD and then wait. With most other DVDs, after about 30 seconds, I’d get a prompt that my Kubuntu 19.04 system had read the DVD and I had several options to proceed (view the files, watch it in VLC, etc.). But with this one, my OS couldn’t even detect that there was a disk in the drive. I tried multiple approaches.

Here’s what K3b indicated:

When I tried loading it in VLC:

And from the command line in VLC:

The problem is not my drive. I regularly load disks in the drive and they work fine, including many disks that have CSS encryption that the libdvd-pkg addresses. But, try as I might, I could not get my computer to even recognize that there was a disk in the drive.

I have a blu-ray player connected to my home entertainment center. Worried that the disk may just be bad, I put it in the blu-ray player and it opened fine. That convinced me that the disk was using some form of encryption that is still not addressed in the libdvd-pkg. I did one final check. I inserted the disk into an old laptop I keep around that has Windows installed on it just to see if this really is a Windows vs. Linux thing. Sure enough, Windows immediately detected it and opened it right up.

After spending a good 5 hours or so trying to find a solution (including installing lots of packages and reading through dozens of threads in Linux forums), I didn’t find a solution. I wrote this post basically just to inform other Linux users that there are some DVDs out there that have encryption that prevent them from being opened in Linux. I’m running the latest version of Kubuntu as of this writing (19.04 beta) with all the suggested packages installed to examine a DVD. But, regardless of what I tried, my OS could not read this disk.

Update 2/3/2020:

A friendly reader (Fabian Echevarria) sent the following:

Last week I came across a DVD similar to that described in your article.

I was able to read the data, first using ddrescue to read to ISO. The resulting ISO also failed but now with a common Title 3 IFO error, which usually isn’t a deal breaker, but in this case continued to prevent play. So I read the raw directory (I normally use 7z/isoinfo) and then pulled each individual chapter from streams that seemed viable, in this case 59 through 72. Running md5sum on the resulting files determined that only two chapters differed between all those stream. A manual review of those two determined which were the correct chapters, which I combined into the final file. The combined file plays fine.

For more information on Fabian’s workarounds, see here.

 737 total views

Linux – Setting Up FTP/SFTP Restricted Access for User

I run a server (Ubuntu 18.04) that hosts about a dozen websites using Linode. Most of the sites are run using WordPress and are my own or sites I manage for friends or family. I do, however, host one for a colleague who actively develops online content for that site.

As WordPress has developed, the ability to upload various file types has slowly been removed for security reasons. As a result, for certain types of files, it is now required to upload them using a different approach. I can do so using SSH, but GUI FTP/SFTP software was going to be easier in this situation as the person responsible for managing that site doesn’t have a lot of knowledge managing a website. I explained to this person, we’ll call her Sharon, that it would be possible for her to upload these files herself using FTP/SFTP. She was worried as she doesn’t know what that is or how to use it. But I explained it and, hopefully, she’ll grow more comfortable with it.

However, I don’t want a novice to gain access to all the files on my server. So, I was faced with the question of how to set up an FTP/SFTP account for someone that is restricted to just one folder – a folder where she can upload stuff and delete files, but with no access to anything else.

Here’s how I did it.

First, you should create a new user group on your server. This can be done with the following command:

sudo addgroup --system GROUPNAME

This will add a new user group called GROUPNAME (I called mine “ftpusers”). If this individual isn’t currently a user on your server, add them as a user as well:

sudo adduser --shell /bin/false USER

Replace “USER” with whatever name you’re using for this individual, for me it was “sharon.” You’ll need to create a password for your USER and fill in some additional information. Then add your USER to your GROUPNAME with the following command:

sudo usermod -a -G GROUPNAME USER

Or my command:

sudo usermod -a -G ftpusers sharon

So, you have now created a new group and a new user and added the new user to the new group. Of course, the next step is to restrict what your new USER can do. In particular, we want the user to have access to just a single directory. Here’s how that is done.

You can create a directory the user can use:

sudo mkdir -p /var/sftp/NEWFOLDER

This folder can be anywhere on your server. I put mine in a subfolder on their wordpress installation:

sudo mkdir -p /var/web/DOMAIN/public/wp-content/uploads/NEWFOLDER

Now, we need to tell the server to restrict USER to this NEWFOLDER when they login. First, let’s give ownership of that folder to the user with the chown command:

sudo chown USER:GROUPNAME /var/sftp/NEWFOLDER

We should also make sure the permissions for the new folder are what we want them to be – read/write for the user and group:

sudo chmod 755 /var/sftp/NEWFOLDER

If you navigate to that folder and check the settings, you should see that the owner is now the USER and the GROUPNAME (you can check with “ls -l”). It’s not a bad idea to also check to make sure that the folder above it is owned by “root” or your primary user, which will prevent your new USER from being able to make changes to that folder.

So far, we have a new USER and GROUPNAME and the user has a folder they can access. However, we need to tell the server that the user needs SFTP access and then need to force them to go to just that one folder when they login with SFTP.

To grant them SFTP access, you need to change the SSH settings:

sudo nano /etc/ssh/sshd_config

This will open the file “sshd_config” with a text editor (nano) so you can make changes. At the end of the file, you want to add the following text:

Match User GROUPNAME
ForceCommand internal-sftp
PasswordAuthentication yes
ChrootDirectory /var/sftp/NEWFOLDER
PermitTunnel no
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no

This allows users in the group GROUPNAME SFTP access to the folder you created for them.

Before you close the nano session with “sshd_config”, you may have to change one other setting. Look for a line that says:

Subsystem sftp /usr/lib/openssh/sftp-server

Mine was not commented out, so that setting was active. However, given the settings we just added to the file, we need to change that. Comment out that line:

#Subsystem sftp /usr/lib/openssh/sftp-server

Below that line, add the following line:

Subsystem sftp internal-sftp

I’m guessing that the original line specified a location for the sftp-server to be used by the server but we want the server to determine the best location for the sftp-server it is going to use and that’s what the second line does. (Alternatively, in the text added to “sshd_config” the line “ForceCommand internal-sftp” could probably be left off, meaning you wouldn’t have to do the step I just described. I haven’t tried that, but it may work.)

Anyway, when you’re done editing the “sshd_config” file, save it and exit from nano.

Finally, to make sure that the new USER is forced into the specified folder when they login, you have to make one more change. This changes the home directory for the user so they are forced into that directory when they login. Here’s the command.

usermod -d /var/sftp/NEWFOLDER USER

This makes the folder you created (NEWFOLDER) the home directory for the USER so, when they log in using SFTP, they will be forced directly into that folder.

There you have it. You have a new user in a group with restricted SFTP access and the user will be forced directly into the folder you created where they can upload, modify, and delete content. They will not have access to anything else on the server, so the rest of your content will be safe.

Acknowledgments: I figured all of the above out with help from these sites: here, here, here, and here.

 1,653 total views,  2 views today

Restarting KDE’s Plasma Shell via Konsole (command line)

As much as I love KDE as my desktop environment (on top of Ubuntu, so Kubuntu), it does occasionally happen that the Plasma Shell freezes up (usually when I’ve been running my computer for quite a while then boot up a game and begin to push the graphics a bit. Often, I just shut down when I’m done and that resets everything. However, there is a quick way to shutdown and restart the Plasma Shell that will bring everything back up.

In KDE Plasma Shell 5.10+, the command to kill the Plasma Shell is:

kquitapp5 plasmashell

In KDE Plasma Shell 5.10+, the command to restart the Plasma Shell is:

kstart5 plasmashell

In earlier versions of KDE 5, the commands were:

killall plasmashell
kstart plasmashell

 4,456 total views,  3 views today