Change Linux Wireless Access Point connection from text terminal with iwconfig


October 8th, 2018

wireless-change-wireless-network-to-connect-to-using-console

If you have configured a couple of Wireless connections at home or work on your Laptop  and each of the remote Wi-FI access points are at different distance (some APs are situated at closer range than others) and your Linux OS keeps connecting sometimes to the wrong AP by default you'll perhaps want to change that behavior, so you keep connected to the Wi-Fi AP that has the best Link Quality (is situatated physically at closest location to your laptop integrated wifi card).
Using a Graphical tool such as Gnome Network Manager / Wicd Network Manager or KDE's Network Manager is great and easy way to do it but sometimes if you do upgrade of your GNU / Linux and the upgrade fails and your Graphical Environment GNOME / KDE / OpenBox / Window Maker or whatever Window Manager you use fails to start it is super handy to use text console (terminal) to connect to the right wiki in order to do a deb / rpm package rollback to revert your GUI environment or Xorg to the older working release.

Connection to WPA or WEP protected APs on GNU / Linux on a low level is done by /sbin/iwlist , /sbin/iwconfig and wpa_supplicant

wpasupplicant and network-manager (if you're running Xorg server).

 

/sbin/iwlist scan
 

 

wlp3s0    Scan completed :
          Cell 01 – Address: 10:FE:ED:43:CB:0E
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=64/70  Signal level=-46 dBm  
                    Encryption key:on
                    ESSID:"Magdanoz"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=00000032cff7c214
                    Extra: Last beacon: 144ms ago
                    IE: Unknown: 00084D616764616E6F7A
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 030106
                    IE: Unknown: 0706555320010B1B
                    IE: Unknown: 2A0100
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : CCMP TKIP
                        Authentication Suites (1) : PSK
                    IE: Unknown: 32043048606C

 

iwlist command is used to get more detailed wireless info from a wireless interface (in terminal this command shows you the wifi networks available to connect to and various info such as the type of Wifi network the Wifi Name / network quality Frequency (is it it spreading the wifi signal at 2.4 Ghz or 5 Ghz frequency) etc.

 

# ifconfig interafce_name down

 

For example on my Thinkpad the wifi interface is wlp3s0 to check what is yours do ifconfig -a e.g.

 

root@jeremiah:~# /sbin/ifconfig -a
enp0s25: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:21:cc:cc:b2:27  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xf3900000-f3920000  

 

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 350  bytes 28408 (27.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 350  bytes 28408 (27.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.103  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::6267:20ff:fe3c:20ec  prefixlen 64  scopeid 0x20<link>
        ether 60:67:20:3c:20:ec  txqueuelen 1000  (Ethernet)
        RX packets 299735  bytes 362561115 (345.7 MiB)
        RX errors 0  dropped 1  overruns 0  frame 0
        TX packets 278518  bytes 96996135 (92.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

Next use iwconfig on Debian / Ubuntu Linux it is part of wireless-tools deb package.

 

root@jeremiah:~# /sbin/iwconfig interface essid "Your-Acess-Point-name"

 

To check whether you're connected to a wireless network you can do:

http://pc-freak.net/images/check-wireless-frequency-access-point-mac-and-wireless-name-iwconfig-linux

root@jeremiah:~# iwconfig
enp0s25   no wireless extensions.

 

lo        no wireless extensions.

wlp3s0    IEEE 802.11  ESSID:"Magdanoz"  
          Mode:Managed  Frequency:2.437 GHz  Access Point: 10:FE:ED:43:CB:0E   
          Bit Rate=150 Mb/s   Tx-Power=15 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
          Link Quality=61/70  Signal level=-49 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:5  Invalid misc:1803   Missed beacon:0


N.B. ! To get a list of all your PC network interfaces you can use cmd:

 

root@jeremiah:/home/hipo# ls -al /sys/class/net/
total 0
drwxr-xr-x  2 root root 0 Oct  8 22:53 .
drwxr-xr-x 52 root root 0 Oct  8 22:53 ..
lrwxrwxrwx  1 root root 0 Oct  8 22:53 enp0s25 -> ../../devices/pci0000:00/0000:00:19.0/net/enp0s25
lrwxrwxrwx  1 root root 0 Oct  8 22:53 lo -> ../../devices/virtual/net/lo
lrwxrwxrwx  1 root root 0 Oct  8 22:53 wlp3s0 -> ../../devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/wlp3s0

show-all-network-interfaces-with-netstat-linux

or use netstat like so:

root@jeremiah:/home/hipo# netstat -i | column -t
Kernel   Interface  table
Iface    MTU        RX-OK   RX-ERR  RX-DRP  RX-OVR  TX-OK   TX-ERR  TX-DRP  TX-OVR  Flg
enp0s25  1500       0       0       0       0       0       0       0       0       BMU
lo       65536      590     0       0       0       590     0       0       0       LRU
wlp3s0   1500       428112  0       1       0       423538  0       0       0       BMRU

 


To get only the Wireless network card interface on Linux (e.g. find out which of the listed above interfaces is your wireless adapter's name), use iw command (that shows devices and their configuration):

 

root@jeremiah:/home/hipo# iw dev
phy#0
    Interface wlp3s0
        ifindex 3
        wdev 0x1
        addr 60:67:20:3c:20:ec
        type managed
        channel 6 (2437 MHz), width: 40 MHz, center1: 2427 MHz
        txpower 15.00 dBm

 

linux-wireless-terminal-console-check-wireless-interfaces-command

  • If you need to get only the active Wireless adapter device assigned by Linux kernel

 

root@jeremiah:~# iw dev | awk '$1=="Interface"{print $2}'

 

To check the IP / Netmask and Broadcase address assigned by connected Access Point use ifconfig
with your Laptop Wireless Interface Name.

show-extra-information-ip-netmask-broadcast-about-wireless-interface-linux

root@jeremiah:~# /sbin/ifconfig wlp3s0
wlp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.103  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::6267:20ff:fe3c:20ec  prefixlen 64  scopeid 0x20<link>
        ether 60:67:20:3c:20:ec  txqueuelen 1000  (Ethernet)
        RX packets 319534  bytes 365527097 (348.5 MiB)
        RX errors 0  dropped 1  overruns 0  frame 0
        TX packets 285464  bytes 99082701 (94.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


As you can see in above 3 examples iwconfig could configure various settings regarding the wireless network interface.

It is really annoying because sometimes if you have configured your Linux to connect to multiple access points, the wifi adapter might keep connecting to an access point that is more distanced from you and because of that the Bandwidth might be slower and that could impact your Internet connectivity, to fix that and get rid of any networks that are automatically set to connect to that you don't want to, just delete the correspodning files (the Wifi file name coincides with the Wireless AP network name).
All stored Wi-FI access points that your Linux is configured to connect to are stored inside /etc/NetworkManager/system-connections/

For example to delete an auto connection to wireless router with a name NetGear do:

 

root@jeremiah:~# rm -f /etc/NetworkManager/system-connections/NetGear

 

For a complete list of stored Wifi Networks that your PC might connect (and authorize to if configured so) do:

 

root@jeremiah:~# ls -a /etc/NetworkManager/system-connections/
Magdanoz
NetGear

LinkSys
Cobra
NetIs
WirelessNet

 

After deleting the required Networks you want your computer to not automatically connect to to make NetworkManager aware of that restart it with:
 

hipo@jeremiah:~# systemctl restart NetworkManager.service


or if you hate systemd like I do just use the good old init script to restart:

 

hipo@jeremiah:~# /etc/init.d/network-manager restart


To get some more informatoin on the exact network you're connected, you can run:

show-information-about-wireless-connection-on-gnu-linux

 

hipo@jeremiah:~# systemctl status NetworkManager.service
● NetworkManager.service – Network Manager
   Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-10-08 22:35:09 EEST; 15s ago
     Docs: man:NetworkManager(8)
 Main PID: 13721 (NetworkManager)
    Tasks: 5 (limit: 4915)
   CGroup: /system.slice/NetworkManager.service
           ├─13721 /usr/sbin/NetworkManager –no-daemon
           └─13742 /sbin/dhclient -d -q -sf /usr/lib/NetworkManager/nm-dhcp-helper -pf /var/run/dhclient-wlp3s0.pid -lf /var/lib/NetworkManager/dhclie

 

Oct 08 22:35:15 jeremiah NetworkManager[13721]:   [1539027315.6657] dhcp4 (wlp3s0): state changed unknown -> bound
Oct 08 22:35:15 jeremiah dhclient[13742]: bound to 192.168.0.103 — renewal in 2951 seconds.
Oct 08 22:35:15 jeremiah NetworkManager[13721]:
  [1539027315.6735] device (wlp3s0): state change: ip-config -> ip-check (reason 'none') [70 80
Oct 08 22:35:15 jeremiah NetworkManager[13721]:
  [1539027315.6744] device (wlp3s0): state change: ip-check -> secondaries (reason 'none') [80 9
Oct 08 22:35:15 jeremiah NetworkManager[13721]:
  [1539027315.6747] device (wlp3s0): state change: secondaries -> activated (reason 'none') [90
Oct 08 22:35:15 jeremiah NetworkManager[13721]:
  [1539027315.6749] manager: NetworkManager state is now CONNECTED_LOCAL
Oct 08 22:35:15 jeremiah NetworkManager[13721]:
  [1539027315.6812] manager: NetworkManager state is now CONNECTED_GLOBAL
Oct 08 22:35:15 jeremiah NetworkManager[13721]:
  [1539027315.6813] policy: set 'Magdanoz' (wlp3s0) as default for IPv4 routing and DNS
Oct 08 22:35:15 jeremiah NetworkManager[13721]:
  [1539027315.6816] device (wlp3s0): Activation: successful, device activated.
Oct 08 22:35:15 jeremiah NetworkManager[13721]:
  [1539027315.6823] manager: startup complete

 

Set mcedit as default text editor for mc (midnight commander) on Linux


October 4th, 2018

set-default-text-editor-for-midnight-commander-to-mcedit-linux-howto

If you're a vim (VI Improved) fan and you set your Linux server / desktop to use VIM as a default text editor, for those who don't know this is done either locally for user (if you're not superuser on remote server) by adding:

export VISUAL=vim
export EDITOR="$VISUAL"

to ~/.bashrc or ~/.bash_profile, e.g.

 

echo 'export VISUAL=vim; export EDITOR="$VISUAL"' >> ~/.bashrc
echo 'export VISUAL=vim; export EDITOR="$VISUAL"' >> ~/.bash_profile

 

or if you're root on the system e.g. it is your Linux desktop / administered by you (debian / ubuntu) server to set VIM as default text editor for all applications with cmd:

 

 # update-alternatives –config editor

 

or if you haven't unset the EDITOR variable the default behavior on some Ubuntu (10.10) etc. versions mc editting would edit with nano text editor.

Just like me however you work also regularly with Midnight Commander (mc) the Linux equivalent of good old Norton Commander you might end up with Midnight Commander opening your files with F4 command with VIM text editor instead of the default.

So here is how to change this behavior in order to end up editting with mcedit any edited file via mc:

mc-menu-options-layout-screenshot

1. Press F9 to Activate the top menu.
2. Press o to Select the Option menu.
3. Press c to Open the configuration dialog.
4. Press i to Toggle the use internal edit option.
5. Press s to Save your preferences.

midnight-commander-configure-options-use-internal-edit-screenshot
Hooray, you're done now mc will use mcedit again as default just like it was intended to be in old times on most GNU / Linux distributions.
Enjoy!
 

Run multiple PHP versions (PHP 5 and PHP 7) with NGINX on the same server howto


October 3rd, 2018

how-to-run-multiple-php-versions-on-same-Linux-server-nginx-webserver-php5-7-logo

It is common sysadmin task to have two versions of PHP running on the same physical or Virtual server to be able to run simultaneously old PHP 5.X legacy applications and PHP 7.X written websites / web applications.

In the past this task was much more complicated than today  you had to compile for example Apache and PHP modules from source and enable it through fastcgi.
Today with the raise of NGINX Web Server and its possibility to run much of the PHP Apps running on top of Apache.
For the sake of this tutorial I'll be using Debian Strecth 9.0.
The reason to use NGINX instead of Apache for this tutorial are numerous, it is light weight (uses less resources – CPU ./ Memory) it is secure smaller in size.
 

1. Install NGINX Web Server

 

# apt-get install –yes nginx 

 

2. Install PHP.7.0 FPM module

 

# apt-get install php7.0-cli php7.0-fpm
 

 

3. Install PHP 5.6 FPM Using external deb repository

Debian default repositories does not include support for PHP 5.6, hence we need to add the respective repositories providing PHP 5.6

 

# apt-get install apt-transport-https

 

# curl https://packages.sury.org/php/apt.gpg | apt-key add –
echo 'deb https://packages.sury.org/php/ stretch main' > /etc/apt/sources.list.d/deb.sury.org.list
apt-get update

 

Next install PHP 5.6 from just added repos

 

# apt-get install –yes php5.6-cli php5.6-fpm

 

4. Check Multiple PHP versions PHP 5 and PHP 7 aree properly installed 

 

# php7.0 -v
PHP 7.0.15-1 (cli)
# php5.6 -v

 

Debian has a default set-up for PHP CLI (Console Interface command) pointing to PHP 7.0, e.g.

 

# php -v
PHP 7.0.15-1 (cli)

 

If you prefer to use as prefer PHP 5.6 instead you can do it with debian update-alternative cmd:

 

# update-alternatives –config php

 

5. Configure both installed PHP -es

Edit /etc/php/7.0/fpm/pool.d/www.conf and look for the listen option. It should equal to /run/php/php7.0-fpm.sock or something alike.
Now do the same for 5.6, it should contain the same with just 5.6 instead of 7.0. Note that it could also be a bind address, i.e. IP address with port (which is performance-wise more suitable for production than sockets). 

 

6. Configuring NGINX webserver


Nginx configuration files are stored in /etc/nginx 

– On Debian the .deb package structure of nginx is is made that all available virtual hosts for nginx just like for Apache are stored  in sites-available directory and production enabled virtualhosts are symlinks to sites-enabled

– Shared configuration for reuse among multiple domains is stored in inside the snippets directory

– fastcgi.conf file contains FastCGI specific variables that are passed to PHP

– The snippets/fastcgi-php.conf is just a helper file to prepare configuration that is passed to PHP module

It is a good idea to remove any unnecessery configuration from /etc/nginx/sites-enabled 
 

7. Create configuration for PHP 7.0


To make simple the test the main (root) directory of nginx will be set to have a simple phpinfo(); file.
 

mkdir /var/www/site-with-php7
echo -e '<?php\nphpinfo();' > /var/www/site-with-php7/index.php 


Then create actual Nginx configuration

 

# vim /etc/nginx/sites-available/site-with-enabed-php7.X

 

server {
    listen 8770 default_server;
    listen [::]:8870 default_server;

    server_name _;
    root /var/www/site-with-php7;
    index index.php;
    location / {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock; # adjust for the listen setting discussed above
    }


As seen from configuration PHP 7 will be serving PHP scripts written for php 7  on TCP port 8870

 

8. Create configuration for PHP 5.6

 

# mkdir /var/www/site-with-php5.6
# echo -e '<?php\nphpinfo();' > /var/www/site-with-php5.6/index.php

 

server {
    listen 8756 default_server;
    listen [::]:8856 default_server;

    server_name _;
    root /var/www/site-with-php5.6;
    index index.php;
    location / {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php5.6-fpm.sock; # adjust for the listen setting discussed above
    }
}

As you see from configuration PHP 5.6 will be serving PHP 5.6 files on TCP port 8756

To enable both NGINX configurations to load enable both nginx vhosts as there is no a2ensite like for enabling NGINX configurations the following  cmd does it
 

# ln -s /etc/nginx/sites-available/site-with-php5.6 /etc/nginx/sites-enabled/
#  ln -s /etc/nginx/sites-available/site-with-php7.0 /etc/nginx/sites-enabled/

To load the new NGINX Virtualhost configurations, restart next:
 

# systemctl reload nginx.service

 

9. Testing NGINX + PHP configuration set-up on port 8870 / 8876

 


– Test NGINX connection on 8876
 

lynx -dump http://localhost:8870

– Test NGINX connection on 8870
 

lynx -dump http://localhost:8870

Both commands should dump you output from PHP 7 (if your server lacks lynx i warmly recommend it, though you can use wget to test).

 

To sum it up


Even though generally it is a bad idea to have 2 instances of application service be it NGINX / Apache from security point of view, it is sometimes a necessity especially when you
or your customers are unwilling to invest money for upgrade of their websites / application infrastructure and if the clients want to keep obsolete PHP code and mix it with a new.
Still migration will be required as you would perhaps want to have some kind of Load Balancer round robin with another NGINX / Apache or Haproxy to make different applications
open under a separate CDN hostname
.

How to check Debian and Ubuntu version codename


October 2nd, 2018

check-linux-os-version-command-howto-check-linux-basic-stuff-lsb_release-command
Once you login to a new server the first thing to do especially if it is a server you never logged in is to check basic things as Kernel version with:

 

root@jeremiah:/home/hipo# uname -a;
Linux jeremiah 4.9.0-8-amd64 #1 SMP Debian 4.9.110-3+deb9u4 (2018-08-21) x86_64 GNU/Linux

 

Check remote server hardware configuration with tools as

 

# dmidecode
# lshw

 

For more check my previous article Get Hardware System Information on Linux

or directly checking things in proc with commands such as:

 

cat /proc/cpuinfo

 

or directly use some custom script such as system_state.sh – 

Next good thing to do is to check Linux install date:

And finally do check the exact codename of Linux on remote server, in the past in many Linux distros this was possible by checking /etc/issue and ./etc/issue.net files, now on Debian based distributions Ubuntu / Debian / Mint this can be achieved with:
 

root@jeremiah:/home/hipo# lsb_release -a
No LSB modules are available.
Distributor ID:    Debian
Description:    Debian GNU/Linux 9.5 (stretch)
Release:    9.5
Codename:    stretch

 

Install Java on Debian 9 Linux howto


September 29th, 2018

java_on-debian-gnu-linux-oracle-virtual-machine-logo

As most system administrators and perhaps most people :), I dislike Java Virtual Machine. However because of its multi-platform support it is largely adopted and so many things are already written in java, even though I hate it I need it to run things every now and then on my personal desktop machine with Debian Linux 9 (Stretch).

From a programmer point of view Java applications are scalable and flexible and from a point of view a person who had to support computers and servers iwth Java it sucks.
To have a running Java Virtual Machine and run Java applications on your Linux PC you could use JRE (the Java Runtime Environment) and JDK (Java Development Kit) which is a set of Java tools and compilers to translate Java code to a .JAR .WAR and the rest of the Java Machine running formats.
openjdk-free-software-java-implementation-for-linux-bsd

OpenJDK (Open JDK) is free (open source) implementation of Oracle Sun Microsystems of Java SE 7 mostly licensed under GPLv2 (but with some linking to a Java class library that is not truly free. OpenJDK includes as components the backend Virtual Machine (HotSpot), the Java Class Library, javac (the java compiler) and IcedTea (which is Redhat's free implementation of Java Web Start plugin.

Install OpenJDK 8 JDK and JRE

OpenJDK is installable by default on Debian and most other distros, to install it on Debian:

 

linux:~# apt-get install –yes -qq default-jdk
linux:~# apt-get install –yes -qq default-jre

 

That would provide your system with support for  java-sdk, java2-sdk, java5-sdk, java6-sdk, java7-sdk, java8-sdk's free implementation.

 

 

linux:~#  java -version

 

 

linux:~# java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

 

 

I have used openjdk but as there are issues with some Java programs because of Java compitability issues. Nowadays most of the timeI choose to usually install the Official Latest Oracle Java 8. The reason is I often have to install on servers application servers such as:

  •  Tomcat
  • JBoss
  • WildFly
  • Jetty
  • Glassfish
  • WebLogic
  • Cassandra
  • Jenkins
     

Install Latest Official Oracle Java 8

java_oracle-virtual-machine-logo

1. Download Oracle Java installable binary

To download latest official release check out Oracle's download page and copy the link to latest Java archive and select the appropriate architecture x64 / 32 bit / arm etc., as of time of writting this article latest Stable Java version is JDK-8U181.

 

linux:~# curl -L -b "oraclelicense=a" -O http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/jdk-8u181-linux-x64.tar.gz

 


Notice the -b "oraclelicense=a" which will pass on to the remote web server accept Oracle's license which is a prerequirement to continue to download.

2. Create directory for Java

 

linux:~# mkdir -p /usr/local/oracle-java-8

 

3. Extract the Java .tar.gz to /usr/local/oracle/java-8 or another directory
where java will live

 

linux:~# tar -zxf jdk-8u181-linux-x64.tar.gz -C /usr/local/oracle-java-8

 

If you have used Java OpenJDK beforehand and installed Oracle Java according to the instructions above you might end up with multiple Javas installed by default, however Debian Linux will have a symlinks to java javac (java compiler), javaws (Java web start).
Thus just executed java will return

 

linux:~# java -version

 

java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

 

4. Set Oracle Java to be default for the Debian system

 

linux:~# update-alternatives –install "/usr/bin/java" "java" "/usr/local/oracle-java-8/jdk1.8.0_181/bin/java" 1500
linux:~# update-alternatives –install "/usr/bin/javac" "javac" "/usr/local/oracle-java-8/jdk1.8.0_181/bin/javac" 1500
linux:~# update-alternatives –install "/usr/bin/javaws" "javaws" "/usr/local/oracle-java-8/jdk1.8.0_181/bin/javaws" 1500

 

An alternative way to set Java to point to Oracle Java instead of OpenJDK is

 

linux:~# update-alternatives –config java

 

There are 2 choices for the alternative java (providing /usr/bin/java).

 

  Selection    Path                                            Priority   Status
————————————————————
* 0            /usr/local/oracle-java-8/jdk1.8.0_181/bin/java   1500      auto mode
  1            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  2            /usr/local/oracle-java-8/jdk1.8.0_181/bin/java   1500      manual mode

 

Press <enter> to keep the current choice[*], or type selection number:

Install Latest Official Oracle Java 10

To install Oracle Java the process is the same:
 

linux:~# wget –header "Cookie: oraclelicense=accept-securebackup-cookie" <paste the download link here> linux:~# mkdir /usr/local/oracle-java-10/ linux:~# tar xvzf jdk-10.0.1_linux-x64_bin.tar.gz -C/usr/local/oracle-java-10 linux:~# update-alternatives –install "/usr/bin/java" "java" "/usr/local/oracle-java-10/jdk-10.0.1/bin/java" 1500 linux:~# update-alternatives –install "/usr/bin/javac" "javac" "/usr/local/oracle-java-10/jdk-10.0.1/bin/javac" 1500 linux:~# update-alternatives –install "/usr/bin/javaws" "javaws" "/usr/local/oracle-java-10/jdk-10.0.1/bin/javaws" 1500

 

Uninstall OpenJDK previous installation

If you choose to use Oracle Java in favor of OpenJDK you might want to also remove the openjdk not to take space on your Hard disk, to so so:
 

linux:~# apt-get remove default-jre

How to reset lost OwnCloud admin password credentials with Linux command


September 28th, 2018

owncloud-change-password-on-owncloud-7-8-linux-howto

Some time ago I've explained how to set-up a personal Cloud via OwnCloud on Linux to be able to access and share your data across all your Phone / Notebook / PCs / Tablet devices and be free from Amazon Cloud slavery.

Now as I haven't used a setup of OwnCloud it seems I forgot my OwnCloud password and besides that I am not sure which email address I filled as a recovery email and was lazy to go through all the OwnCloud MySQL database tables, thus I looked for
other ways to recover the forgotten password. Finally I ended up using the command line, below is how OwnCloud 7 admin password can be easily reset (recovered) with occ php command:

 

root@pcfreak:/var/www/owncloud# sudo -u www-data php occ user:resetpassword admin
PHP module intl not installed.
Please ask your server administrator to install the module.

 

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/owncloud/lib/private/Console/Application.php:135
Stack trace:
#0 /var/www/owncloud/console.php(105): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /var/www/owncloud/occ(11): require_once('/var/www/ownclo…')
#2 {main}root@pcfreak:/var/www/owncloud# apt-cache search php|grep -i intl
php-intl – Internationalisation module for PHP [default]
php-symfony-polyfill-intl-grapheme – Symfony polyfill for intl's grapheme_* functions
php-symfony-polyfill-intl-icu – Symfony polyfill for intl's ICU-related data and classes
php-symfony-polyfill-intl-normalizer – Symfony polyfill for intl's Normalizer class and related functions
php7.0-intl – Internationalisation module for PHP
php-symfony-intl – limited replacement layer for the PHP extension intl
php-symfony-locale – deprecated replacement layer for the PHP extension intl
php5-intl – internationalisation module for php5
root@pcfreak:/var/www/owncloud# apt-get install php7.0-intl
Четене на списъците с пакети… Готово
Изграждане на дървото със зависимости       
Четене на информацията за състоянието… Готово
Следните пакети са били инсталирани автоматично и вече не са необходими:
  docutils-common docutils-doc gcj-4.9-jre-lib gnat-4.9-base libasn1-8-heimdal libavcodec56 libavformat56 libavresample2 libavutil54 libbind9-90 libboost-program-options1.55.0 libboost-python1.55.0 libcompress-raw-bzip2-perl libcompress-raw-zlib-perl libcrypt-openssl-random-perl
  libdnet libdns-export100 libdns100 libegl1-mesa-drivers libexiv2-13 libgcj15 libglew1.10 libgnat-4.9 libgnutls-openssl27 libgphoto2-port10 libgphoto2-port10:i386 libhcrypto4-heimdal libhdb9-heimdal libheimbase1-heimdal libhx509-5-heimdal libimobiledevice4 libinput5 libintl-perl
  libintl-xs-perl libirs-export91 libisc-export95 libisc95 libisccc90 libisccfg-export90 libisccfg90 libjson-c3 libkrb5-26-heimdal libllvm3.5:i386 libllvm3.8 liblognorm1 liblwres90 libntdb1 libopenvg1-mesa libplist2 libprocps3 libpsl0 libroken18-heimdal librrd4 libtfm1
  libusbmuxd2 libvpx1:i386 libwebpdemux1 libwebpdemux2 libwebpmux1 libwind0-heimdal libwings2 libwraster3 libwutil3 libx264-142 libxtables10 linux-image-3.16.0-4-amd64 python-characteristic python-docutils python-ndg-httpsclient python-ntdb python-pil python-pygments
  python-pyinotify python-roman python-twisted-lore python-twisted-mail python-twisted-names python-twisted-news python-twisted-runner python-twisted-words
Използвайте „apt autoremove“ за да ги премахнете.
Следните НОВИ пакети ще бъдат инсталирани:
  php7.0-intl
0 актуализирани, 1 нови инсталирани, 0 за премахване и 1 без промяна.
Необходимо е да се изтеглят 124 kB архиви.
След тази операция ще бъде използвано 523 kB допълнително дисково пространство.
Изт:1 http://ftp.uk.debian.org/debian stable/main amd64 php7.0-intl amd64 7.0.30-0+deb9u1 [124 kB]
Изтеглени 124 kB за 1с (93,7 kB/сек)        

 

Selecting previously unselected package php7.0-intl.
(Reading database … 210111 files and directories currently installed.)
Preparing to unpack …/php7.0-intl_7.0.30-0+deb9u1_amd64.deb …
Unpacking php7.0-intl (7.0.30-0+deb9u1) …
Processing triggers for libapache2-mod-php7.0 (7.0.30-0+deb9u1) …
Setting up php7.0-intl (7.0.30-0+deb9u1) …

Creating config file /etc/php/7.0/mods-available/intl.ini with new version
Processing triggers for libapache2-mod-php7.0 (7.0.30-0+deb9u1) …
root@pcfreak:/var/www/owncloud# occ user:resetpassword admin
bash: occ: командата не е открита
root@pcfreak:/var/www/owncloud# sudo -u www-data php occ user:resetpassword admin
Enter a new password: 
Confirm the new password: 
Successfully reset password for admin
root@pcfreak:/var/www/owncloud# 
 

 

 

root@pcfreak:/var/www/owncloud# sudo -u www-data php occ user:resetpassword admin
Enter a new password: 
Confirm the new password: 
Successfully reset password for admin


owncloud-screenshot-on-my-debian-gnu-linux-in-chrome-browser

That's all now I can login again to WEB UI interface and use my owncloud-client to synchronize content from my notebook to OwnCloud

 

This method should work work on resetting password of OwnCloud version 7, 8 and 9 on Linux (Fedora, Ubuntu, CentOS and RHEL) if OwnCoud was installed using rpm / deb packages. 
 

How to change hostname in Ubuntu, Debian and Redhat based Linux machine


September 27th, 2018

change-hostname-on-any-linux-distributions-universal-way-to-change-linux-hostname-howto

The hostname is set at the time when a Linux OS is installed by the respective installer (set-up scripts) on a bare-metal server or  virtual machine. 

Historically to change the hostname in most GNU / Lonux distributions (Debian / Ubuntu / Fedora / CentOS etc.) it was as easy as:

1. Getting your current setting for hostname with hostname command
 

hipo@jeremiah:~$ hostname –fqdn
jeremiah


Logging to the remote machine via ssh.
 

 

 

ssh user@whetever-host.com


3. Editting /etc/hosts and substituting with the new desired hostname
 

 

vim /etc/hosts
127.0.0.1   localhost
127.0.0.1   jeremiah

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

4. Run 

/etc/init.d/hostname.sh start


5. Run command
 

hostname your-new-desired-hostname


and logout and login again to the host to make the new hostname active for the ssh session

Since around 2015 a new way was introduced to change hostname in Ubuntu 13.04 onwards and Fedora 21 and Debian 8 / 9 the way to set a new hostname comes again up to editting
/etc/hosts

and running command:
 

hostnamectl set-hostname your-new-desired-hostname

 

 

On Redhat based Linux distributions and Red Hat Enterprise Linux to change the hostname you will also need to edit:
 

vim /etc/sysconfig/network

NETWORKING=yes
HOSTNAME="domain.com"
GATEWAY="192.168.0.1"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"


Another universal way to edit hostname on any Linux distribution is to use sysctl cmd like so:
 

sysctl kernel.hostname

sysctl kernel.hostname=your-desired-hostname

 

Change GNOME lock time settings in Linux


September 26th, 2018

http://pc-freak.net/images/change-gnome-lock-time-settings-debian-linux-screenshot

In GNOME 3.X The screen lock time setting is set either to 1 minute 15 minutes or NEVER
So what if you would like to,

Set the gnome screen lock settings value to 30 minutes or one Hour

Here is how:

For 30 minutes lock screen setting:

 

linux:~$ gsettings set org.gnome.desktop.session idle-delay 1800

 

Set GNOME lock time to 1 hour

 

linux:~$ gsettings set org.gnome.desktop.session idle-delay 3600

 

The setting is set in seconds so quickest way to calculate is to divide by 60 (seconds), you can calculate easily the time you like with BC (arbitrary precision calculation language) like so:

 

linux:~$ echo '3600/60' | bc
60

 

Lets say you would like to set your screen to lock every 3 hours, the delay value to set in org.gnome.desktop.session would be:

 

linux:~$ echo '3600*3' | bc
10800

 

Once you set the value to a different than the 3 recognized ones would show in GNOME Control Center as Never (depending on the distro).
 

Reset gnome forgotten keyring password – Fix annoying reoccuring keyring password prompt


September 26th, 2018

gnome-keyring-password-error-fix-solution-howto-gnupg-error-after-changing-user-password-linux-desktop-user

If you're on Debian Linux and have a user account and you changed the password you might be unpleasantly surprised by a constantly occuring prompt to reinput the keyring stored old password.
You might be wondering how to reset the gnome keyring password to stop that annoying pop-up prompt from bittering your days.
The simplest fix is to delete all stored passwords and reset the keyring stored values. That's in case if you don't have other important passwords saved.

This is done by simply creating a backup of the old keyring just in case if you have something important stored you can do that with:

 

cd ~/.local/share/keyrings/
cp login.keyring login.keyring.backup

 


Then delete the keyring store file:

 

rm  -f ~/.local/share/keyrings/login.keyring

 

Under some GNU / Linux distrubutions such as Linux Mint deleting the keyring file will not work on such an alternative method is to use seahorse (a frontend program to GnuPG (GNU Privacy Guard), that is doing key management  for GNOME desktop users.

 

hipo@jericho:~$ seahorse

 

seahorse-gnu-gpg-and-password-management-gui-tool-gnome-desktop-environment-debian-linux-screenshot
 

For older Linux distributions like Ubuntu 12.10 e.g. in GNOME 2, the correct path to keyring file is ~/.gnome2/keyrings/
 

rm -f ~/.gnome2/keyrings/*

 

 

Linux: GNOME Flashback missing Desktop Icons fix – Hack to add desktop icons via gnome-shell in GNOME 3.28 onwards


September 24th, 2018

how-to-fix-workaround-gnome-3.30-missing-desktop-icons-on-linux

I just upgraded my notebook fom Debian Stretch 9.5 Linux to Buster (current Testing Debian release). All went fine except I got a lot of headaches because it seems in Buster the GNOME Flashback 3.30 which I use has removed the support for Show Desktop Icons in Nautilus because of some migration reasons of Nautilus to a newer version 4, (hopefully that would be temporary) from gnome-tweak-tool whose package now contains no binary for gnome-tweak-tool, instead an equivalent tool now is called gnome-tweaks and this tool is no longer working under Gnome Flashback but only with GNOME Classic 3.30 and the regular GNOME 3.30 launcher available from gdm3 (the Gnome Display manager).
 

1. Displaying Missing Desktop icons on GNOME version 3.30


The way to display Desktop icons in GNOME 3.28 onwards at the moment of writting this post and the whole issue with the removed handling of Desktop icons in Nautilus is explained well by Carlos Soriano a gnome shell extension developer in his blog post Desktop icons goes beta.

The good guy C. S. wrote  the his desktop icons gnome shell extension which is on github.com
To use it you have to fetch it and enable it by fetching the repo source code to gnome-shell extensions directory:
 

hipo@linux:~$ cd ~/.local/share/gnome-shell/extensions
hipo@linux:~$ git clone https://gitlab.gnome.org/World/ShellExtensions/desktop-icons
hipo@linux:~$ mkdir 'desktop-icons@csoriano'
hipo@linux:~$ mv desktop-icons/* 'desktop-icons@csoriano'/
hipo@linux:~$ rm -rf desktop-icons/


Now you should use the gnome-tweaks command tool to enable the new added gnome-shell extension.

 

 

hipo@linux:~$ gnome-tweaks


gnome-tweak-on-debian-testing-linux-screenshot

Once enabled your Desktop icons will appear as usual as seen in below shot, the downside this solutions is icons as seen in below screenshot is that pictures doesn't have Thumbnail pictures generated … and icons when kept on with mouse over can move only in a selected square like perimeter (when moved left / right / up down side). That "woody" icon movement sucks a bit but much better than no icons at all.

gnome-3.30-general-desktop-solved-missing-icons-desktop-screenshot-on-debian-linux

 

2. Displaying Missing Desktop icons in GNOME Flashback 3.30

 

I really love GNOME Flashback as it used to be a good replacement for Linux MATE (which is the fork of GNOME2 and not bad but lacks Metacity Window Manager and some of the Eye Candy that GNOME 3 and beside that even MATE had to be slightly hacked to make look more like Classical GNOME 2 – for more on that check my previous article Fixing Mate Adwaita Theme problems on Debian and Ubuntu). 

At the moment when I tried to run gnome-tweaks under a GNOME Flashback session I got the following error:

 

hipo@jericho:~/.local/share/gnome-shell/extensions$ gnome-tweaks 
WARNING : Shell not installed or running
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/gtweak/app.py", line 30, in do_activate
    self.win = Window(self, model)
  File "/usr/lib/python3/dist-packages/gtweak/tweakview.py", line 38, in __init__
    self._model.load_tweaks(self)
  File "/usr/lib/python3/dist-packages/gtweak/tweakmodel.py", line 104, in load_tweaks
    mods = __import__("gtweak.tweaks", globals(), locals(), tweak_files, 0)
  File "/usr/lib/python3/dist-packages/gtweak/tweaks/tweak_group_general.py", line 14, in <module>
    _shell_not_ubuntu = _shell.mode != 'ubuntu'
AttributeError: 'NoneType' object has no attribute 'mode'

 

In regular GNOME session gnome-tweaks works fine and with the help of an GNOME Shell Extension addon it is possible to add the Missing Desktop icons however the only working fix for GNOME FlashBack 3.30 is to substitute nautilus (the default GNOME file manager) with NEMO (which is The Official file manager for Cinnamon Desktop Environment).
Thanksfully this is done relatively easy and all I had to do is to use a little "hack", e.g. install nemo.

 

root@linux:~# apt-get install –yes -qq nemo

 

And add a new auto-launcher for gnome that launches nemo file manager instead of nautilus.

To add the auto-launcher in GNOME I had to add a file with following content:

 

[Desktop Entry]
Type=Application
Name=Nemo
Comment=Start Nemo desktop at log in
Exec=nemo-desktop
OnlyShowIn=GNOME;
AutostartCondition=GSettings org.nemo.desktop show-desktop-icons
X-GNOME-AutoRestart=true
NoDisplay=true

 

to ~/.config/autostart/

For those who don't know GNOME has this handy way to set an autostart programs by using the specific .desktop extension files that have to be placed under $HOME/.config/autostart (where $HOME = the logged in user home directory).

The one liner to do so is:

 

echo '[Desktop Entry]
Type=Application
Name=Nemo
Comment=Start Nemo desktop at log in
Exec=nemo-desktop
OnlyShowIn=GNOME;
AutostartCondition=GSettings org.nemo.desktop show-desktop-icons
X-GNOME-AutoRestart=true
NoDisplay=true' >> ~/.config/autostart/nemo.desktop

 

Then I had to restart my GNOME FlashBack session (e.g. Log Out and Login with a new session) and the icons appeared.

classic-gnome-flashback-debian-gnu-linux-hipos-desktop-screenshot

The downside of this dirty workaround is that desktop icons even though showing up couldn't be moved (rearranged) freely on any location of desktop (are pretty much static) and the even worser  fact about this hack is you can't actually copy paste easily copy files from your Desktop within another desktop folder … 
 I know that's shitty but at the moment there is no better solution and this is better than nothing at all.

 

P.S. I tried downgrading my Debian Testing to Stable Stretch Linux again with the idea to use the old GNOME 3.22 that the Stable Debian distro provides but, ended up with a lot of mess after experimenting to downgrade using /etc/apt/preferences file records and substitution in /etc/apt/sources.list to include the stable .deb repository and apt dselect and aptitude package management tools. Officially downgrades are not encouraged and supported by Debian, but I hoped I could relatively easily do it by manually fixing the broken dependencies after removing debian packages manually combined with short for bash loops like I did in the past, but it seems this time I broke the system worse, so I could hardly return it back to normal operation in upgrading packages with a lot of manual hacking with apt-get and few one liner scripts. Thus I abandoned as a fix the possiiblity to downgrade Testing Debian to stable, I even considered switching from GNOME desktop environment to something more light as OpenBoxCinnamon / XFCE and gave them one more try but the results weren't nice, I reconsidered again to go back to using the Good Old GNU Step Window Maker as a GNOME alternative which in my opinion is still a great GUI environment for security crackers / sysadmins /hackers (programmers) and eventually perhaps I will switch back to using it, because GNOME is becoming more and more bloated with the years and I can hardly stand it … I mean I did not expected GNOME to be developed in the shitty Mobile Interface  (Unity) way, I have been a loyal user to GNOME for so many years and have lived trhough  all its mess over the years, its painful to see how the good and efficient GNOME 2 went the bad broken road of changing completely concepts and interface in GNOME 3.x
 

3. Closure

GNOME Desktop icons has been with GNOME users already for about 15+ years so IMHO the missing ability to add them easily through gnome tweak tool or Gnome Control Center is a absurd stupidity and killed at least 5 times out of my time to solve and the solution is far from good … I understand that in future the GNOME developers want to make GNOME as modular as possible through GNOME Shell Extensions however if you're removing such an important functionality that's for ages in most mainstream operating systems such as M$ Windows / Mac OS is an insanity. Through my quick research online I found the Missing Desktop Icons is experienced by other people on other Linux distros besides Debian I saw complains by Ubuntu / Fedora and Arch Linux users in forums and mailing lists.
What puzzles me why the reaction of such a major complained are not seriously considered by GNOME developers, especially after all the problems with transition from GNOME 2 -> GNOME 3 which already pushed a lot of GNOME users to move from GNOME to KDE / MATE  (like in Linux Mint whose GUI is based on Linux Mint). Definitely such a general issues would drive further enthusiasts from GNU / Linux and makes a great harm to the Free Software software community.
Hopefully the missing desktop icons hell will be solved in upcoming GNOME releases.