XP-rience

Something that I'd like to share with you!

Sunday, July 09, 2023

SSH private key authentication with WinSCP and PuTTY Gen

No comments :

Simplify your login process by using SSH keys for authentication when you are connecting to your server.

1st step is to run the PuTTYGen software and generate a key.


Save the private key to a file.
Next, login into you server through SSH and create "~/.ssh" directory if it doesn't exists.
chmod the directory to 700.
[applmgr@vm-centos7 ~]$ cd ~
[applmgr@vm-centos7 ~]$ mkdir -p .ssh
[applmgr@vm-centos7 ~]$ chmod 700 .ssh
[applmgr@vm-centos7 ~]$ ls -al
total 12
drwx------. 6 applmgr applmgr 119 Jul  9 20:27 .
drwxr-xr-x. 4 root    root     36 Jul  9 20:05 ..
-rw-r--r--. 1 applmgr applmgr  18 Oct 31  2018 .bash_logout
-rw-r--r--. 1 applmgr applmgr 193 Oct 31  2018 .bash_profile
-rw-r--r--. 1 applmgr applmgr 231 Oct 31  2018 .bashrc
drwxrwxr-x. 3 applmgr applmgr  18 Jul  9 20:06 .cache
drwxrwxr-x. 3 applmgr applmgr  18 Jul  9 20:06 .config
drwxr-xr-x. 4 applmgr applmgr  39 Jul  4 19:01 .mozilla
drwx------. 2 applmgr applmgr   6 Jul  9 20:27 .ssh
Create "authorized_keys" if it doesn't exists.
chmod it to 600 and edit the file, in my example, using "vi"
[applmgr@vm-centos7 ~]$ cd .ssh/
[applmgr@vm-centos7 .ssh]$ touch authorized_keys
[applmgr@vm-centos7 .ssh]$ chmod 600 authorized_keys
[applmgr@vm-centos7 .ssh]$ vi authorized_keys

Copy and paste (or add new line) the content of the public key into this file.


Save the file and now run your WinSCP, enter hostname, username and click "Advanced ..."


Under "SSH" > "Authentication", check the "Allow agent forwarding", and select the privates key file that you've saved just now.


And "login".




Sunday, April 02, 2023

PostgreSQL installation & connecting it to to Oracle SQL Developer/HeidiSQL

No comments :

Install PostgreSQL DB, in my example here, installing it under Ubuntu by referring to below URL.

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-20-04

Login to your shell and execute below command lines.

$ sudo apt update
$ sudo apt install postgresql postgresql-contrib

Now enable remote access to your PostgreSQL by editing 2 files under "/etc/postgresql/12/main/".

https://support.cpanel.net/hc/en-us/articles/4419265023383-How-to-enable-remote-PostgreSQL-access

Note that "12" is the version number. Change it according to the installed version number.

Edit "postgresql.conf" file and add...

listen_addresses = '*'

Edit "pg_hba.conf" file and add...

host all all 0.0.0.0/0 md5

Now start your PostgreSQL DB using "systemsql" command.

$ sudo systemctl start postgresql

Before you can connect to the PostgreSQL , you need a user. Create PostgreSQL user "puser" with below command line.

$ sudo -u postgres createuser --interactive

And you also need a DB to start with. Create PostgreSQL DB named "pdbase" with below command line.

$ sudo -u postgres createdb pdbase

Create Linux user matching with the PostgreSQL user "puser".

$ sudo adduser puser

Switch user to "puser" and run "plsql" to login to the PostgreSQL DB.

$sudo -u puser psql -d pdbase

You should now get the "plsql" prompt as below indicating that you have successfully login to the your PostgreSQL DB.

pdbase=#

Use "\l" to list databases or use "\dt" to list tables, these is just to make sure the DB is running fine.

pdbase=# \l

pdbase=# \dt

Now alter password for "puser", This password will be used to connect through remote connection such as Oracle SQL Developer or HeidlSQL.

pdbase=# ALTER USER puser WITH PASSWORD 'mypass';

Example connecting from SQL Developer

https://www.oracle.com/database/technologies/jdbc-migration.html

Please refer above URL to add JDBC driver to your SQL developer.

Fill up necessary info such as user/pass/host/port/db and hit Test/Connect.


Example connecting from HeidiSQL.

Same goes to HeidiSQL, fill up necessary info such as user/pass/host/port/db and hit Open



Saturday, July 30, 2022

Red Hat OpenShift port forwarding to access MySQL at port 3306

No comments :



Still continuing from my first post about Red Hat OpenShift, here is how to do port forwarding from your locahost port 3306 to MySQL hosted under Red Hat OpenShift. This is to enable the connection to the MySQL using your favorite MySQL client. I'm using HeidiSQL.

1st, OC login to your environment by copying the "oc login" command.


Copy the token displayed.


Open CMD prompt and paste the copied token, assuming that you have already installed the OC tool (OpenShift CLI)


Now, list available pods that you have there.


RSH into you MySQL using "oc rsh <podname>" as below. You should get the shell prompt.


Get user/pass/host/port values from the environment variables using "env|grep <string>" command.


  • MYSQL_PASSWORD = ************
  • MYSQL_USER = userBUW
  • MYSQL_SERVICE_HOST = 172.30.117.29
  • MYSQL_SERVICE_PORT = 3306

Exit RSH with "exit" command and start "oc port-forward <podname> <port>" command as below.


Output "Forwarding from .... > 3306" indicates that the port forwarding is currently active. 

Now, try to access the MySQL using you favorite client. Example below is using HeidiSQL.




Thursday, July 28, 2022

Setting up Joomla 4 and MySQL under Red Hat OpenShift

No comments :


Continue from my first post about Red Hat OpenShift, here is how to setup Joomla 4/PHP/MySQL under Red Hat OpenShift.

MySQL 

Start by adding MySQL from template.


Most of the fields will be auto generated. Note that the database name is "sampledb"

Continue and wait for the pod to up & ready


Get your OC login. List down available pods. RSH into your MySQL (running) pod and grep the environment variables for MYSQL_SERVICE_HOST, MYSQL_USER & MYSQL_PASSWORD

get IP address

C:\Users\USER>oc get pods

NAME             READY   STATUS      RESTARTS   AGE

mysql-1-deploy   0/1     Completed   0          110s

mysql-1-mrqtl    1/1     Running     0          107s

C:\Users\USER>oc rsh mysql-1-mrqtl

sh-4.4$ env | grep MYSQL_SERVICE_HOST

MYSQL_SERVICE_HOST=172.30.117.29

sh-4.4$ env | grep USER

MYSQL_USER=userBUW

sh-4.4$ env | grep PASSWORD

MYSQL_PASSWORD=XxXxXxXxXxXx

PHP

Now add PHP images from template.


Use joomla4 PHP files from Github repository below.

https://github.com/ermihusni/joomla4

Note that I've tried the actual Joomla repository but somehow failed. You may try if you want to.

https://github.com/joomla


Wait for the PHP pod to up & ready, and then open the PHP page to start Joomla setup.

Joomla

Insert "sampledb" as database name, the one that we've got from MySQL setup before.

Set the hostname, username & password from the MySQL server environment variable RSH grep before.


    Confirm as the website owner by deleting the autogenerated file named "_Joomla*".


RSH into the pod and delete it from the "installation" directory.

C:\Users\USER>oc get pods

NAME                         READY   STATUS      RESTARTS   AGE

joomla-001-1-build           0/1     Completed   0          3m50s

joomla-001-d9ff8c8b6-dwsgd   1/1     Running     0          2m35s

mysql-1-deploy               0/1     Completed   0          13m

mysql-1-mrqtl                1/1     Running     0          13m


C:\Users\USER>oc rsh joomla-001-d9ff8c8b6-dwsgd

sh-4.4$ cd installation/


sh-4.4$ ls

INSTALL  LICENSE.txt  _JoomlahFHOLvETv9AotNDHiqiuN.txt  ...


sh-4.4$ rm _JoomlahFHOLvETv9AotNDHiqiuN.txt

Continue the setup and congratulation!



Saturday, July 23, 2022

How to connect phpMyAdmin to MariaDB under Red Hat OpenShift

No comments :


It is a container platform built for an open hybrid cloud.

Get your trial account from https://www.redhat.com/en/technologies/cloud-computing/openshift if you haven't do so.

Like me, I'm getting myself a developer sandbox with a trial length of 30 days just to understand how to play around with it.

First step is to add a database:


Pick MariaDB (Ephemeral), it is a database without persistent storage & data stored will be lost upon pod destruction. Good enough for testing:


Hit "Create" to continue:


For phpMyAdmin we will be using docker image from https://hub.docker.com/r/startxfr/openshift-phpmyadmin/

Copy the docker image name below:
startxfr/openshift-phpmyadmin

 

Now, add "Container Images" for phpMyAdmin


Paste the docker image name & hit "Create"


Now, get back to the MariaDB and verify the environment settings.



 

sh-4.4$ env|grep MARIA
MARIADB_SERVICE_HOST=172.30.1.41
MARIADB_PORT=tcp://172.30.1.41:3306
MARIADB_PORT_3306_TCP_ADDR=172.30.1.41
MARIADB_PORT_3306_TCP_PROTO=tcp
MARIADB_SERVICE_PORT_MARIADB=3306
MARIADB_PORT_3306_TCP=tcp://172.30.1.41:3306
MARIADB_SERVICE_PORT=3306
MARIADB_PORT_3306_TCP_PORT=3306
sh-4.4$ 

Verify the ConfigMap. This is where the database username & password being shared to the ConfigMap. From below we can see that they are being shared to mariadb, database-user & database-password.


Now check the environment variables use by the phpMyAdmin to connect to the MariaDB



Look into the "config.inc.php" file on how it is getting the database user & password from the environment variables.


Scroll down until to get see below section

if(getenv('MARIADB_SERVICE_USER') != '') {
$i++;
    $cfg['Servers'][$i]['extension'] = 'mysqli';
    $cfg['Servers'][$i]['auth_type'] = 'config';
    $cfg['Servers'][$i]['host'] = getenv('MARIADB_SERVICE_HOST');
    $cfg['Servers'][$i]['port'] = getenv('MARIADB_SERVICE_PORT');
    $cfg['Servers'][$i]['user'] = getenv('MARIADB_SERVICE_USER');
    $cfg['Servers'][$i]['password'] = getenv('MARIADB_SERVICE_PWD');
    $cfg['Servers'][$i]['compress'] = false;
    $cfg['Servers'][$i]['AllowNoPassword'] = false;
}

So we now know that phpMyAdmin is getting database username & password from  MARIADB_SERVICE_USER for database username & MARIADB_SERVICE_PWD as database password.

Add both MARIADB_SERVICE_USER and MARIADB_SERVICE_PWD to phpMyAdmin environment variables by linking them to ConfigMap.



Now try to open the phpMyAdmin web page.



Good luck trying!