Find your Thinkpad (X1) model type in linux

Problem

You would like to find out the exact model from your Thinkpad X1 laptop, by using your linux command line.

Solution

Use the following command:

kosmas:$ sudo dmidecode | grep -A3 '^System Information'
[sudo] password for kosmas: 
System Information
        Manufacturer: LENOVO
        Product Name: 20HRCTO1WW
        Version: ThinkPad X1 Carbon 5th

Problems using snap autossh

Problem

You would like to use autossh to keep a connection open (ie database) between two hosts, but while the ssh equivalent command to start a tunnel works, the autossh does not.

You might be seeing the following errors (using AUTOSSH_DEBUG=1):

autossh[7471]: ssh exited prematurely with status 255; autossh exiting

or if you look at /var/logs/syslog you could also see entries like the following:

 apparmor="DENIED" operation="open" profile="snap.autossh.autossh" name="/home/autossh/.ssh/id_rsa.pub" pid=7447 comm="ssh" requested_mask="r" denied_mask="r" fsuid=1002 ouid=1002

Solution

You have used snap to install autossh which is not allowed by apparmor.

Remove the snap package and install autossh as a normal debian package:

sudo snap remove autossh
sudo apt install autossh

Connect your Shivr bluetooth headphones in Linux

To connect your new Shivr headphones but it would probably work with other bluetooth headphones too, find the MAC address from your headphones (by connection with an Android device first) and do the following from the command line:

sudo apt install bluez-tools
bt-device -l (that will list the available devices)
bt-device -c AA:11:22:33:44:BB

and make sure you change your Music Player Daemon Output (Audio Volume Settings -> Applications) settings to use your new headphones.

Get a list of directories with user permissions

Problem

You want to run a command in a hosted server but you don’t have su permissions. There are directories that have different owners/permissions, so you would like to see them.

Solution

Use the tree command and save the output in a file if you have many directories:

tree -pufid /home/directory_to_check > /home/user/permissions.txt

taken from the answer here: https://unix.stackexchange.com/a/82374

Automatic emails using bash and sendgrid

Problem

You would like to be able to automatically send some emails (ie reports) from a linux server, using a bash script that runs in cronjob, without installing an email server on the linux server.

Solution

  • Create an account in Sendgrid and follow the directions for using WebAPI with curl
    here
  • Set up your bash script to use the API key and have a script like the following. If you want to use big or multiple files you will need to use a temporary file for the base64 encoding, as in the example below, as there is a limit in curl.
  • Add your script to crontab
  • curl: (7) Failed to connect to localhost port 80: Connection refused

    Problem

    You would like to access a host set up with nginx after adding your own vhost configuration file in /etc/nginx/conf.d/myfile.smth, but you get Connection refused.

    Solution

    Make sure that your nginx configuration file has the .conf extension as /etc/nginx/conf.d/myfile.conf.