DEV Community

Hari Bantwal
Hari Bantwal

Posted on • Updated on

Useful Commands

SSH from Public Instance to Private Instance

ssh -t -o ProxyCommand="ssh -i id_rsa ubuntu@PUBLICIP -W %h:%p" -i id_rsa ubuntu@PRIVATEIP

Create CRT

openssl req -new -newkey rsa:2048 -nodes -keyout domain.co.key -out domain.co.csr

Boot Strap Command for nginx on Ubuntu on OCI

#!/bin/bash
sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx.service
systemctl status nginx
sudo iptables -I INPUT -p tcp --dport 80 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -I OUTPUT -p tcp --sport 80 -m conntrack --ctstate ESTABLISHED -j ACCEPT

https://ubuntu.com/tutorials/install-and-configure-nginx#4-setting-up-virtual-host

Command to Install docker/compose on Oracle Linux and run potsgres on OCI

#!/bin/bash
sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install docker-ce --nobest -y
sudo systemctl enable --now docker
sudo usermod -aG docker root
sudo systemctl disable firewalld
sudo sudo curl -L "https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo sudo mv /usr/local/bin/docker-compose /usr/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose
sudo docker run -d -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=changeme postgres

sudo docker exec -it postgres bash

Command to Install and Configure Apache, PHP 8, MySQL, and WordPress on OCI

#!/bin/bash
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT
sudo netfilter-persistent save
sudo apt update
sudo apt -y install apache2
sudo systemctl restart apache2
sudo apt -y install php
sudo apt -y install php-mysql php-curl php-gd php-zip
sudo systemctl restart apache2
sudo adduser $USER www-data
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R g+rw /var/www/html

Command to Point the Wordpress server to point to NFS

#!/bin/bash
sudo systemctl stop apache2
sudo mv /var/www /var/www-old
sudo mkdir /var/www
sudo mount -t nfs 20.0.1.94:/wordpress /var/www
sudo systemctl restart apache2

When WP is migrated to new Host, wp-admin still points to the old host. How to fix this.

mysql> show databases;
mysql> use <wordpressdb>;
mysql> desc wp_options;
mysql> select option_name from wp_options;
mysql> select option_name from wp_options where option_name = 'siteurl';
mysql> update wp_options set option_value = 'http://<NEW HOST>' where option_name ='siteurl';
mysql> select * from wp_options where option_name = 'home';
update wp_options set option_value ='http://<NEW HOST' where option_name = 'home';

WP website migrated to HTTPS, images are gone. Add the following lines in wp-config.php

if (isset($_SERVER["HTTP_X_FORWARDED_PROTO"] ) && "https" == $_SERVER["HTTP_X_FORWARDED_PROTO"] ) {
$_SERVER["HTTPS"] = "on";
}

How to import and export the Mysql Dump

`mysqldump --no-tablespaces -h 20.0.1.45 -u wordpress -p wordpress > wpdump.sql

mysql -h 20.0.1.137 -u wordpress -p wordpress < wpdump.sql `

https://docs.oracle.com/en-us/iaas/developer-tutorials/tutorials/wp-on-ubuntu/01-summary.htm

https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql

https://www.tecmint.com/fix-error-2003-hy000-cant-connect-to-mysql-server-on-127-0-0-1-111/

https://serverfault.com/questions/139323/how-to-bind-mysql-server-to-more-than-one-ip-address

https://stackoverflow.com/questions/8020297/mysql-my-cnf-file-found-option-without-preceding-group

https://stackoverflow.com/questions/19101243/error-1130-hy000-host-is-not-allowed-to-connect-to-this-mysql-server

CREATE USER 'bob'@'10.0.0.0/255.0.0.0' IDENTIFIED BY 'password123';

https://libreswan.org/

CLI Spot Check

oci iam user get --user-id ocid1.user.oc1..userid

Encrypt and decryprt using OCI Vault

IAM

Allow group '' to manage vaults in compartment HADR
Allow group '' to manage keys in compartment HADR

OCI CLI

plaintext=$(echo "Lets look at the OCI KMS Demo" | base64)
echo $encryptedtext
encryptedtext=$(oci kms crypto encrypt --plaintext $plaintext --key-id <ocid> --endpoint https://<cryptoendpoint>-crypto.kms.eu-frankfurt-1.oraclecloud.com)
export cipher=$(echo $encryptedtext | jq -r '.data | .ciphertext')
decryptedtext=$(oci kms crypto decrypt --ciphertext $cipher --key-id <ocid> --endpoint https://<cryptoendpoint>-crypto.kms.eu-frankfurt-1.oraclecloud.com)
echo $decryptedtext
export b64encodedPlainText=$(echo $decryptedtext | jq -r '.data | .plaintext')
echo $b64encodedPlainText | base64 --decode
Enter fullscreen mode Exit fullscreen mode

Top comments (0)