Linux Tips : Creating a symlink

I have now been fully using Manjaro Linux for around eight months now, mostly never having to use my Windows 10 except for the program Garmin Express that I need sometimes.

Today I wanted to create a symlink (symbolic link) from an original file in a folder to another folder

In Manjaro Linux and probably other Linux distribs wallpapers are in more than one folder, the original files and symlinks in different folders

I had added wallpaper image that I wanted to use in  my /usr/share/backgrounds/wallpapers-2018/  folder
I wanted to add the symlink link to the /usr/share/backgrounds/xfce/ as this folder contained symlinks of all the original files in the wallpaper-2018 folder, why? I do not know, but as it must be of use somewhere and as I like playing and learning I thought that I would create the symlink

Of course, Linux Not being Windows the copy, drag and drop doesn’t work as it needs root permissions

So a quick Google around showed me that I needed the ln -s command in terminal

So I typed in terminal what I had learned :

sudo ln -s /usr/share/backgrounds/wallpapers-2018/Wallpaper_1.jpeg /usr/share/backgrounds/xfce/

This is just sudo ln -s ‘source’ ‘target’

sudo so that it will ask your password when you hit the Ok button
Source being where your original fil is, the complete address (/usr/share/backgrounds/wallpapers-2018/Wallpaper_1.jpeg)
Target being where you want the symlink to be created (/usr/share/backgrounds/xfce/)

This effectively created a symlink in my target/destination folder /usr/share/backgrounds/xfce/ but I noticed that it was different from the other files having the little ‘arrow’ but also a ‘cross’, and when checking found that it was a ‘broken’ symlink

Now I had to delete this file, doh needs to have root permission to do that ….
sudo rm /usr/share/backgrounds/xfce/Wallpaper_1.jpg
Careful here rm is a dangerous command, it deletes full stop and doesn’t ask are you sure etc etc

Hours later, many google pages later I came across an article saying that I had to ‘be in’ the target/destination folder when doing the ln -s command for it to work

Ok that’s fairly easy so in the terminal I just typed
cd /usr/share/backgrounds/xfce/ (my target folder where I wanted the symlink to be)

Now being in the target folder I redid the
sudo ln -s /usr/share/backgrounds/wallpapers-2018/Wallpaper_1.jpeg /usr/share/backgrounds/xfce/

my symlink file was now created correctly and this time only having the little arrow showing me that it was a symlink and correctly linked to the original file, Oh yes 🙂

So easy except having to know that I had to cd to be in my target folder for the symlink to be correctly created

Hoping that this might save you some hours of googling around….

Again I’m a beginner in Linux, I use it / play with it and sometimes find things that should be easy but aren’t and are as clear as mud, so help this helps

Linux Tips : SSMTP

I’ve now been using Manjaro Linux since the start of 2020

So far so good, I’m getting used to the way it works. Linux quirks that can be a real pain to learn or get used to. Coming from Windows after using it for over 30 years, for about 90% of the time I’m pleased with it.

Unlike Windows it’s harder to use, to modify or create files, folders in certain places etc can be a real pain, because of Linux’s security, I suppose it’s a good thing, but wrapping you head around how to modify a dopey file or to add a line can be more than just a pain in the ass.

In a these posts, I’m trying to write down things that I found really hard to do or learn, or very time consuming to do, hoping that maybe of some use to someone.

This tip is how to get Cron to send an email when the job has been completed (in my case a backup evry hour from 9h – 22h, sadly as like many of Linux’s programs this is far from easy.

Being in Manjaro, I first has to install ssmtp, this the easy part…

Once installed you will find a folder at /etc/ssmtp/
Inside will be two files, ssmtp.conf & revaliases. As usual these have only root permissions and so you need to modify them as root and not as user.

In the conf file once open you just need to paste the following under the line # The full hostname (for info when a line has a # in front of it, this means that it’s a commented line not a command line)

ssmtp.conf
Paste this
hostname=user-manjaro
TLS_CA_File=/etc/ssl/certs/ca-certificates.crt
root=mymail@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=user-manjaro
UseSTARTTLS=YES
AuthUser=mymail@gmail.com
AuthPass=123456
FromLineOverride=YES
AuthMethod=LOGIN

I’ll try and explain what needs to be modified in the above lines

ssmtp.conf
user-manjaro (open a terminal, type hostname
mymail@gmail.com replace with your gmail address
AuthPass=123456 need if you use gmail with 2FA, you have to create a special password under gmail security’s settings to let ssmtp / Linux send yurself mails (https://support.google.com/accounts/answer/185833?hl=en)

So once these details have been sent you can modify the second file Revaliases
Paste this
root:mymail@gmail.com:smtp.gmail.com:587
localusername:mymail@gmail.com:smtp.gmail.com:587

Once this has been done, you can modify your cron file and instead of
MAILTO=””
MAILTO=mymail@gmail.com

See https://minty95.wordpress.com/2020/04/27/linux-tips-cron/

Now when your cron job runs, you will receive a mail, sadly the subject of the cron command line , it’s long and a mess : but it’s better than nothing

Email subject line : Cron <root@usermanjaro> root rsync -avhW /home/trevor/Documents/* /run/media/trevor/BackUp_1/Copy_trevor_home_documents

Linux Tips : CRON

I’ve now been using Manjaro Linux since the start of 2020.

So far so good, I’m getting used to the way it works. Linux quirks that can be a real pain to learn or get used to. Coming from Windows after using it for over 30 years, for about 90% of the time I’m pleased with it.

Unlike Windows it’s harder to use, to modify or create files, folders in certain places etc can be a real pain, because of Linux’s security, I suppose it’s a good thing, but wrapping you head around how to modify a dopey file or to add a line can be more than just a pain in the ass.

In a these posts, I’m trying to write down things that I found really hard to do or learn, or very time consuming to do, hoping that maybe of some use to someone.

This tip is how I backup certain of my files and folders that I need or want or keep if ever I reinstall Linux , I’m talking about everyday files and folders here, mostly from My Documents folder, not a system backup, using a specific program like TimeShift for instance.

Cron

A Simple way to back up files and folders other than a system backup, or backups that are compressed, all mixed in one big file and complicated use

I wanted to backup my Document folder and it’s contents from my internal Linux system HD to another internal HD.
As with Windows if my system crashes, Windows or now Linux, I don’t normally bother  about repairing a system, I just wipe the HD and do a fresh install as it’s nearly always quicker, especially with Linux (no bothering with keys, and checking with MS to see if it’s a real copy or not) Just download the latest ISO and hop it’s done. Reinstalling Linux is hours quicker than reinstalling Windows

For my everyday backups with Windows 10. I used a rather good program called Bvckup2, cost about $30 and was by far the easiest to set up and run.
Of course this doesn’t run in Linux and after a couple of questions on the Telegram group and a IRC chat group that I’m often use, people suggested me a couple of native Linux programs, which I downloaded and tried but found them all over complicated (Linux….), or outdated, or weren’t very good, then someone talked about ‘Cron’ amongst other things…. and of I went starting to learn a little, very little about this Cron thingy

This took a lot of time to get my head around it, and need to ask many questions on the forums to understand the basics, but finally, it was quite simple…… (remember above : “but wrapping you head around how to modify a dopey file…”) after having tried a few specific programs I found that it was by far the best and easiest for what I needed.
Cron works with just a file placed in the ‘cron.d’ folder which is in your /etc/ folder.

It’s just a file (for us Windows guys its just a text file without the .txt extension) that you write and drop it in the Cron.d folder on the system disc.
Linux being Linux, and just a tad more complicated that Windows because of permissions that are needed the file ‘needs Root permissions’ as the owner, but when you write a file in Linux the owner is you and not root. So you need to know how to create file with root permissions.

Note : I’m not a Linux geek, and know next to nothing about it, but as I play with it, retired… have time… I sometimes manage to get things working, Cron for instance. It took me yonks to get it to work, reading on the web, the forums the chats. So I hope this post will help you and save some time.

For starters

Don’t forget I’m using Manjaro XFCE so maybe your Linux isn’t the same as mine.

In the file system you should have a folder cron.d, it’s not hidden so easy to find

/etc/cron.d/

In this folder you need to create a file with root permissions (important root permission, if you do with user permission, it won’t work) and name it, mine is called ‘Copy_docs’, Once this done, you can write the cron commands in the file. Here is one of mine.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=””
MAILFROM=””
10 09-22 * * * root rsync -avhW /home/trevor/Documents/* /run/media/trevor/BackUp_1/Copy_trevor_home_documents

Now most of this I haven’t a clue what it means, but it works. I know that the mailto and mailfrom is so that you can send and receive mails when it runs, but you need add more soft to your Linux and I tried but didn’t understand it , which is a shame as a mail telling that it’s run, would be nice, will try again one day. (Update got that working, will try and explain in a new post)

This part I just copied from examples that I found elsewhere, The first two lines I haven’t a clue what they mean.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=””  (having the “” means the Cron skips this)
MAILFROM=””  (having the “” means the Cron skips this)

This part is a little is what I created
10 09-22 * * * root rsync -avhW /home/trevor/Documents/* /run/media/trevor/BackUp_1/Copy_trevor_home_documents
That’s all one long line in my file, but WordPress breaks it into two lines because there’s a space between the /* and /run

10 09-22 * * *
This is cron timing, here I tell it to run at 10 minutes past the hour, every hour from 9am to 10pm, as with everything be careful her , I once added one too many *, nothing worked after……
https://crontab.guru/ Use this site to change, or setup your timing, it’s fairly easy to understand, basically cron time is ‘5 stars’, each star meaning something.

root rsync -avhW / Not sure about all this, rsync is what cron uses for copying and the avhW it’s to do with copying permissions , so I was told. It works….

(from) home/trevor/Documents/*
My home folder ‘Documents’ (it’s the same as the My Document Folder in Windows), the /* after means everything in it, all sub folder and files.

(To) /run/media/trevor/BackUp_1/Copy_trevor_home_documents
My BackUp destination, /run/media/trevor/BackUp_1/Copy_trevor_home_documents

So there you go, A small text file (no .txt) after the name of the file in the cron.d folder in /etc/cron.d and my files are copied easily

Just for fun, here’s another file for you
Copies my music files once a month at 11:45 on the first day of each month, From Back_1 to BackUp (BackUp a third HD BackUp in my setup)

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=””
MAILFROM=””
45 11 1 * * root rsync -avhW /run/media/trevor/BackUp_1/All_Music/* /run/media/trevor/BackUp/Music/

Hope this helps, after writing this I’ve got the MailTo and MailFrom to work, will do a another post as again it’s quite complicated, welcome to Linux 🙂

See : https://minty95.wordpress.com/2020/04/27/linux-tips-ssmtp/

Once done replace MAILTO=”” with MAILTO=mymail@gmail.com

Please don’t hesitate if you have a question, I not very good a Linux, but I’m learning …… and if I can help…

Linux Tips : Yubikey U2F – 2FA protection. Adding a second key

Here’s a quick ‘how-to’ use a Yubikey or rather two or more Yubikeys

Recently I started using a small wafer-thin USB key that gives me a secure U2F connection to several programs or web sites, like Google Gmail, Facebook, Dropbox etc with 2AF security, these days a must.

Yubikey.com

Setting one up isn’t that hard, basically, you choose the two-factor authentication (2FA) option on the site or the application that you want to use it with, follow the blah blah until you get to scan a QR code that you zap with your YubiKey authenticator app on your phone.

(you can also use another authenticator app, such as Authy) but …….

….but while you’re securing a web site or a program/application, secure the app on your phone as well. Authy or/and most apps will show you or anyone the 6 codes generated on the app just by opening it, so could be potentially dangerous.

Yubi’s authenticator app will only show the codes if you have a Yubi key next to the phone by NFC contact or plugging it into the phone.

The app like all authenticator apps will show a 6 digit code for 30 seconds, after 30 seconds this code changes.

On the website, after scanning the QR code it will be expecting you to insert the 6 figure code and hit enter, and voilà this will then ‘tie’ the app, or web site to your key and the authenticator app.

Again, so that the authenticator app shows the codes, it needs to be next to the key if NFC, or the key plugged in depending on the model you have bought, in my case the 5 NFC

Now where it becomes a little complicated is if you want to have two keys or more (like me)

I bought a second key couple of weeks later, wanting one on my key-ring with my keys and another next to my computer at home.

So I ordered the same one, YubiKey 5 NFC, being naive, I thought it would just work, touch the authenticator app with the second key and it would work, being the same as the other one, doh stupido… of course it didn’t

Reading up quickly on the YubiKey site didn’t make any sense to me, so I spent some time playing around until I sussed it out

So let’s start again
Log in to one of the sites you have already done with the first key, Dropbox for example, Cancel the 2FA option and delete it from the app. Then start all over again.

This time when you get to the QR code to be scanned, scan it with the YubiKey authenticator app (as before) Save the site that’s just been added, by pressing the save button, you also need to re touch the phone with one of the keys to save it. Then RE SCAN the QR code again, this time save it again using the other key, it won’t add another login (there will only one instance Dropbox for instance on the app, but both keys will now work/be linked with it, don’t forget to validate the scanned QR with the 6 digit code shown on the app.

So scan, add it to the app, re scan add it to the app and validate the scanned QR with the 6 digit code being shown

Now when you open the YubiKey authenticator app again on the phone, either key will open it and show the stocked codes, FB, Dropbox etc

Certain sites such a Gmail, BitWarden use these keys, and in the settings, you can add as many as 5 or 6 keys directly on the site (Twitter only one), also certain don’t need the authenticator app or van use it as well, just rely on the key being connected directly the USB socket and being touched (there’s a little ‘touch pad’ on the key) to open the web site or app. That’s why I wanted one always next to the computer and the other with my keys in my bag or pocket near my phone

The authenticator app also works on a PC, in my case Linux. (a page explain how to get the app to work in Linux on my previous post)

As above, the key just needs to be plugged into the USB socket and touched when you start the program so that the codes are shown, the same principle as the app on the phone

So now two keys are working, so if ever you lose or break one, you have the other that can be used, giving you time to buy another, for info they are not expensive at around 50 euros. Note that is quite important as some apps, like the Yubikey authenticator CANNOT be used without a key.

Please don’t hesitate to leave any comments or critics, or suggestions if you find anything wrong.