TWL's Algorithms

Archive for the ‘Linux Administration’ Category

Add shortcut to Ubuntu 20 launcher / Show Applications menu

How?

Go to this folder via file explorer or command line:

~/.local/share/applications

Then create a file named your_application.desktop and put the following contents

[Desktop Entry]
Type=Application
Name=Eclipse
Comment=Eclipse Integrated Development Environment
Icon=/opt/eclipse/icon.xpm
Exec=/opt/eclipse/eclipse
Terminal=false
Categories=Development;IDE;Java;
StartupWMClass=Eclipse

Replace the file’s contents with information relevant to your application.

Then save it.

When you click the “Show Applications” link, type your application’s name in the search box and you should see the link appearing.

Cannot connect to database through JDBC

When this was called,

java.sql.DriverManager.getConnection( connection, props)

We got the following exceptions

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

Caused by: javax.net.ssl.SSLHandshakeException: DHPublicKey does not comply to algorithm constraints
at sun.security.ssl.DHCrypt.checkConstraints(DHCrypt.java:237)
at sun.security.ssl.ClientHandshaker.serverKeyExchange(ClientHandshaker.java:765)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:268)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1052)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:987)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:89)
… 134 more

How? It’s probably due to your SSL connection to the database is using an algorithm that is not as secured as JRE allows.

Solution

Open the file:

/usr/lib/jvm/java-8-oracle/jre/lib/security/java.security

Then look for this line:

jdk.tls.disabledAlgorithms=SSLv3, RC4, MD5withRSA, DH keySize < 1024, \
EC keySize < 224, DES40_CBC, RC4_40, 3DES_EDE_CBC

and replace it with

jdk.tls.disabledAlgorithms=SSLv3, RC4, MD5withRSA, \
DES40_CBC, RC4_40, 3DES_EDE_CBC

DH keySize and EC keySize restrictions were removed.

Start process on linux boot using systemd

How? Create a file called /etc/systemd/system/test.service , renaming test to your process’ name accordingly.

[Unit]
Description=A Service that should start after network is up and vmware-tools runs
After=network.target vmware-tools.service

[Service]
User=wuliangx
Restart=always
Type=simple
ExecStart=/home/wuliangx/my_process/start.sh

[Install]
WantedBy=multi-user.target

Run this command to start the process.

systemctl start test

Verify that process is started

systemctl status test

Make the process start on boot

systemctl enable test

Reboot the system and run this command again to verify that process is running

systemctl status test

 

 

Setting Eclipse launcher icon in ubuntu

Installed Eclipse ubuntu, but when you launch it, a grey icon appears in the launcher. How?

First, find the eclipse icon by going to where you installed eclipse, e.g.
/home/user/eclipse

then typing the command to find the icon:

find . -name eclipse*.png

For me, the result is

./configuration/org.eclipse.osgi/688/0/.cp/eclipse32.png

Next, open
/home/user/.local/share/application/eclipse.desktop

then change the line starting with Icon= to

Icon=/home/user/eclipse/configuration/org.eclipse.osgi/688/0/.cp/eclipse32.png

How to install Ruby on Rails in CentOS 7

  1. Login as root
  2. Install the requisite libraries by using the following command
    yum -y install gcc gcc-c++ make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel
  3. Download the latest version of ruby to your host. E.g.
    wget https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.0.tar.gz
  4. Extract and install ruby
    tar -zxvf ruby-2.4.0.tar.gz
    cd ruby-2.4.0
    ./configure
    make && make install
  5. Install rails
    gem install rails
  6. Install a javascript runtime, e.g. therubyracer
    gem install therubyracer
  7. Create a directory for your ruby on rails site and change directory to that path.
    rails new blog
    cd blog
  8. Open Gemfile and add this below the first line
    gem 'therubyracer'
  9. Start rails
    rails server
  10. Open a browser and go to localhost:3000 to verify that your site is working.

 

Install vlc player for CentOS 7

Currently running on CentOS 7.3.1611

  1. Install epel
    yum -y install epel-release
  2. Update
    yum -y update
  3. Install nux-dextop
    rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
  4. Install vlc
    yum -y install vlc

CentOS 7 on high dpi screen in VMWare (Macbook 2013 retina)

The screen resolution of CentOS 7 looks very small in VMWare.

How to increase it?

  1. Log in as root.
  2. Run xrandr to see the available screen resolutions.
  3. Modify the following command accordingly to change the screen resolution.
    xrandr –output Virtual1 –mode 1920×1200
  4. Modify the following command to make the menus and fonts look bigger after changing the resolution.
    xrandr –output Virtual1 –scale 0.65×0.65

 

See console messages in CentOS 7

 

Open /etc/default/grub and configure the GRUB_CMDLINE_LINUX option. Delete rhgb quiet from the string.

Run this command to save changes.

grub2-mkconfig -o /boot/grub2/grub.cfg

 

CentOS 7 remove home partition and extend root partition

How?

  1. Unmount home partiton

    umount /home

  2. Show logical volumes and look for the home volume.

    lvdisplay

      .
      .
      --- Logical volume ---
      LV Path                /dev/myhost/home
      LV Name                home
      VG Name                centos
      .
      .
  3. Remove the home volume

    lvremove /dev/myhost/home

  4. Verify that you have free space.

    vgs

  5. Take note of where your root is located

    df -h

    Filesystem                Size  Used Avail Use% Mounted on
    /dev/mapper/myhost-root    50G  1.2G   49G   3% /
    .
    .
  6. Resize root partition to reclaim all free space.

    lvextend -l +100%FREE /dev/mapper/myhost-root

  7. Remove the line containing the home directory from /etc/fstab
  8. Reboot.

Raspbian launch application with terminal on boot

To start a program automatically in a terminal upon boot, open the file /etc/xdg/lxsession/LXDE-pi/autostart then add this line as the second last line (must be above the screensaver command):

@lxterminal –command “/home/pi/opencv/a.out”

Next, access the desktop, open a terminal then run lxsession-edit

Uncheck LXPolKit

Click OK

Then reboot.