Wednesday, March 4, 2020

Please check if the configured key or specified key file is a valid SSH Private Key - Rancher Kubernetes

Solution next error Rancher on Centos8:

Please check if the configured key or specified key file is a valid SSH Private Key. Error: Error configuring SSH: ssh: no key found


Steps:

WORKSTATION.

Save the key of your nodes on workstation.

Step 1 — Create the RSA Key Pair


ssh-keygen

Enter and enter doesn't write anything.

Step 2 — Copy the Public Key to CentOS Server


ssh-copy-id username@remote_host

Copying Public Key Using SSH

cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"


Check connect with ssh without password.











References:



Saturday, February 29, 2020

MySQL - Create user, Database and access remote(CentOS 7)

When you need to create a new user on mysql you need to login with user root, for that you need to login from console use the next command.

mysql -u user -p your_password


Create user.


*Localhost

CREATE USER 'your_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'your_user'@'localhost' WITH GRANT OPTION;

*RemoteAccess 

CREATE USER 'your_user'@'your_ip' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'your_user'@'your_ip' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Note: if the access is denied still when you run command line above then you need the configuration file /etc/my.cnf and add next line on the file bind-address:your_ip. and then you need tu restart mysql.

#mysql
systemctl restart mysql 

#mariadb
systemctl restart mariadb.service

Next: open the required port 3306, run the next command.

iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT

In the end: Save the iptables configuration

service iptables save

Create Databases.


CREATE DATABASE your_database;


GRANT ALL PRIVILEGES ON your_database.* TO 'your_user'@'localhost';








References:
https://linuxize.com/post/how-to-create-mysql-user-accounts-and-grant-privileges/
https://www.inmotionhosting.com/support/website/how-to-create-a-database-using-mysql-from-the-command-line/
https://www.hostinger.com/tutorials/mysql/how-to-grant-remote-access-mysql-vps
https://support.infrasightlabs.com/article/host-is-not-allowed-to-connect-to-this-mysql-server/
https://serverfault.com/questions/626922/no-mysqld-or-mysql-server-after-mariadb-server-install


Monday, February 17, 2020

Installing Java 8 on CentOS 7


Installing Java 8 on CentosOS 7.

Steps:

Step 1: Update

yum -y update

Step 2: Install Java 8


yum install java-1.8.0-openjdk


Step 3:  Verify Java is Installed

java -version


Step 4: Java alternatives (choose Java 1.8..)



update-alternatives --config java

update-alternatives --config javac

update-alternatives --config javaws


Step 5: Environment

vim .bash_profile

Inside on file, copy path your jdk, example:

export JAVA_HOME=/usr/lib/jvm/YOUR_JDK/jre/bin/java


Refresh the File:
Source .bash_profile

echo $JAVA_HOME























Thursday, January 23, 2020

SSO OAuth2 Spring Boot2 Security JDBC Authentication


I share example how to integration OAuth2 - Spring Boot2 - Security - JDBC Authentication.


Technologies used:

1. Spring Boot 2.0.3.RELEASE
2. Maven 4
3. Java 8
4. OAuth2
5. Eclipse: Oxygen.1.a Release (4.7.1a)
6. Spring Tools Suite (STS) 4
7. MySql

Code on GitHub:

https://github.com/HenryXiloj/SSO-OAuth2-SpringBoot2-JDBC

Steps:

Step 1:

Create tables on mysql:

CREATE TABLE users 
  ( 
     username VARCHAR(50) NOT NULL PRIMARY KEY, 
     password VARCHAR(100) NOT NULL, 
     enabled  BOOLEAN NOT NULL 
  ); 

CREATE TABLE authorities 
  ( 
     username  VARCHAR(50) NOT NULL, 
     authority VARCHAR(50) NOT NULL, 
     CONSTRAINT fk_authorities_users FOREIGN KEY(username) REFERENCES users( 
     username) 
  ); 

CREATE UNIQUE INDEX ix_auth_username ON authorities (username, authority); 


Step 2: Insert your user, example:

For insert password on Databases you need to passwordEncoder, for example use Test.java for generate passwordEncoder:




Resul is : $2a$08$sqfU5.UM.oEqgzVniREsvOsQ9eDtSD/xX8RXT2Bc4AmXWHo4fcchG


INSERT INTO users 
VALUES      ('henry', 
             '$2a$08$ykZFaf/pmTxnShaj5dqXZeWXiK3JJSJr5f20hqiVGSO35KNyQ0lgO' 
             /*123*/, 
             true); 

INSERT INTO authorities 
            (username, 
             authority) 
VALUES     ('henry', 
            'ROLE_ADMIN'); 



Step 3:

On the proyect spring-security-sso-auth-server change the configuration in application.yml




Step 4:

Run 2 proyects on Eclipse or if you prefer use command line on console:

First: auth server

Righ click on proyect -> Run As -> Spring Boot App

Expose on port: 8081



Second: sso-ui

Expose on port: 8082




Step 5:

http://localhost:8082/ui/




























References:

https://www.baeldung.com/sso-spring-security-oauth2
https://www.baeldung.com/spring-security-jdbc-authentication
https://mkyong.com/spring-security/spring-security-form-login-using-database/





Saturday, January 18, 2020

Permission Denied (publickey) error when I push (GitHub)


I share solution next error:

Permission Denied (publickey)' error when I push!

Steps:

Step 1:

Search de folder .ssh, you find the folder on your user:  (if the folder doesn´t exist then you need to create the folder with the command mkdir inside on your_user)

Linux:  /home/my_user/.ssh
Windows: C:\Users/my_user/.ssh


Step 2: Run the next command and press enter: (Leave blank what they ask)

ssh-keygen


Step 3:

Before command generate the file id_rsa.pub, open the file by command or any editor and copy of content.

Step 4:

Go to your profile on  GitHub:

Choose Settings --> SSH and GPG Keys --> New SSH Key --> Copy content from file id_rsa.pub


And try to git push again.


















References:
https://gist.github.com/adamjohnson/5682757


Wednesday, December 11, 2019

Kotlin SpringBoot 2 Spring Data JPA RESTful Web Service

Hi everyone.

I share example how to integration Kotlin - Spring Boot2 - Spring Data JPA-RESTful Web Service and CRUD example.


Technologies used:

1. Spring Boot 2.2.2.RELEASE
2. Gradle 2.x
3. Java 8
4. Eclipse: Oxygen.1.a Release (4.7.1a) or  IntelliJ Community
5. Spring Tools Suite (STS) 4
6. Postman
7. MySql

Code on GitHub:

https://github.com/HenryXiloj/Kotlin-SpringBoot2-RESTful


Steps:

Step 1:

Execute next script on MySql

CREATE TABLE users 
             ( 
                          id       INT(11) NOT NULL auto_increment, 
                          username VARCHAR(255) NOT NULL, 
                          password VARCHAR(255) NOT NULL, 
                          created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() on 
             UPDATE CURRENT_TIMESTAMP(), 
                    PRIMARY KEY (id) 
             )

Step 2: Import project on Eclipse or IntelliJ


Eclipse:


IntelliJ:  File -> open --> choose folder backend




Righ click on project  Gradle -> Refresh Gracle project (Eclipse)



IntelliJ:

View -> Tool Windows -> Gradle -> Righ click on project -> Refresh Gradle dependencies



Step 3.

Run project from directory on console next command:

./gradlew bootRun



Run project from IntelliJ :

View -> Tool Windows -> Gradle -> Execute Gradle Task -> gradle bootRun




Step 4: Test.


GET  (by default)
GET all users

http://localhost:8080/ws/users





GET user by id.

http://localhost:8080/ws/users/1




POST user (save)

http://localhost:8080/ws/users





PUT user (update user)

http://localhost:8080/ws/users/1




DELETE user.

http://localhost:8080/ws/users/1



Great :).















References:








































Wednesday, June 12, 2019

Stop and Start JAR file in background CMD on Windows using bat file

I share example how to execute JAR file in background or if you want execute command line in background on Windows.

Steps:

1. Create file start.bat and add next code.

@echo OFF
cd C:\path_your_jar
start javaw -jar your_jar.jar


2. Create file stop.bat and add next code. for example if you application up in the port 9000 then you find the port and PID and kill.

@ECHO OFF                                                                           
FOR /F "tokens=5" %%T IN ('netstat -a -n -o ^| findstr "9000" ') DO (
SET /A ProcessId=%%T) &GOTO SkipLine                                                 
:SkipLine                                                                           
echo ProcessId to kill = %ProcessId%
taskkill /f /pid %ProcessId%

or

if you want to find jar and to change the next line.

@ECHO OFF                                                                           
FOR /F "tokens=1" %%T IN ('jps -m ^| find "jar" ') DO (
SET /A ProcessId=%%T) &GOTO SkipLine                                                 
:SkipLine                                                                           
echo ProcessId to kill = %ProcessId%
taskkill /f /pid %ProcessId%

That is it.




🔐AWS → Google Cloud Workload Identity Federation with Terraform

  Eliminating Service Account Keys for Cross-Cloud Workloads Managing identities across cloud providers is often more challenging than manag...