Thursday, March 19, 2020

GIT Tips


1.  Install git

sudo apt install git

2. create file .ssh

sudo mkdir /home/your_user/.ssh  

3. On folder .ssh run next command, (enter and enter doesn't write anything).

ssh-key

4. copy content on file id_rsa.pub

cat /home/your_user/.ssh/id_rsa.pub

5. Open in your browser GitHub or GitLab

GitHub: https://github.com/settings/keys  -> New SSH key

GitLab:https://your_ip_or_hostname/profile/keys --> Add and SSH Key

6. Clone branch or specific branch

Any branch:
git clone <remote-repo>
Specific branch:
git clone --single-branch --branch <branchname> <remote-repo>

8. Discard unstaged changes

git stash

9. Git Checkout Specific file

git checkout <branch_name> -- <paths>

10. Override comment in commit

git commit --amend -m "My_new_comment"

11. Remove local commits

git reset --hard origin/<branch_name>

12. To rollback to commit

git reset --hard sha1_id

13. Create GitHub Branch from Commit

Clone the Repository:
git clone https://github.com/your-username/your-repository.git
cd your-repository
Find the Commit Hash:
git log
Create a New Branch:
git checkout -b new-branch-name commit-hash
Push the New Branch to GitHub:
git push origin new-branch-name

14. Pull All Branches Automatically

To configure your Git repository to automatically track all remote branches, you can set the following:

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin

This ensures that all remote branches are fetched and mirrored locally.

15. Long path file:

git config --system core.longpaths true

17. Recovery

git stash list

git stash apply stash@{0}   # most recent
git stash apply stash@{6}   # oldest 6 = n

 




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:








































🚀 Spring Boot 3.5 → 4.0.3 Migration Summary

Import Changes, API Adjustments & Compatibility Results Migration summary from Spring Boot 3.5 → 4.0, including breaking changes, depend...