Tuesday, November 17, 2020
Check laptop battery percentage using terminal
Tuesday, November 10, 2020
Using putty via cmd
Putty is an ssh client that many windows users used to connect to ssh server. Due to the complexity of ssh protocol, the settings in putty is also quite complex.
Here I want to show some examples where you can use putty via the cmd. You can simply copy below commands and paste it inside your cmd, do some changes like IP, username and port, and you are good to go without having to go through many steps to complete some simple task such as setting up a dynamic tunnel.
The first thing that you have to do before using putty via cmd is, to install putty. Just download the installer from here, and install it using the usual double click on installer method.
Once installed, fire up your cmd.
Below are some basic scenario to use putty (if you are familiar with the linux openssh client, the options are almost identical)
Scenario 1: Connecting to a remote server (with ip 10.10.10.10):
cmd> putty user@10.10.10.10
Scenario 2: Forward a remote port to you local machine, in this case, forwarding port 22 on 10.10.10.10 to port 9999 on your local machine
cmd> putty user@10.10.10.10 -L 9999:localhost:22
Scenario 3: Forward a local port to a remote machine, in this case, forwarding port 22 in localhost to 9999 in remote machine
cmd > putty -R 9999:localhost:22 root@10.0.0.16
Scenario 4: Create a socks5 proxy (dynamic tunnel) on port 8888 in localhost via the remote machine. This is useful if we want to browse addresses that only can be accessed by the remote machine, but the remote machine does not have an internet browser.
cmd> putty user@10.10.10.10 -D 8888
Scenario 5: Connect to a remote machine, via port other than 22. In this case, sshd is running on port 9999
cmd> putty -P 9999 user@10.10.10.10
There you go, 5 scenarios where you can use putty via command line. Hope this will make your life easier when using putty. Ciao!
Sunday, November 8, 2020
Checking your public IP from terminal
Sometimes, when you are setting up a linux machine, there is a need to know what IP our machine is being connected to the public internet. There are many websites that provide this kind of service, but below are some of my favorites that work well with commands.
To be able to use this, we need a text based web browser. We will use curl in this case. Install curl if your machine does not have one.
# yum install curl -y
To get our ip address, run curl like below. Choose whichever you like :).
$ curl ipecho.net/plain
210.210.210.210
$ curl icanhazip.com
210.210.210.210
{
"ip": "210.210.210.210",
"city": "Kuala Lumpur",
"region": "Kuala Lumpur",
"country": "MY",
"loc": "3.1390,101.6869",
"org": "AS4818 Digi Telecommunications Sdn. Bhd.",
"postal": "50505",
"timezone": "Asia/Kuala_Lumpur",
"readme": "https://ipinfo.io/missingauth"
}
$ curl ipinfo.io/ip
210.210.210.210
$ curl ipinfo.io/city
Kuala_Lumpur
Simple http/https proxy using squid
This is a basic proxy setup, whereby you practically does not have to do any settings.
First, install squid in our machine with address 10.0.0.10
# yum install squid -y
Then, start squid service
# systemctl start squid
By default squid runs on port, 3128, so we will allow 3128/tcp on our firewall
# firewall-cmd --add-port 3128/tcp
# firewall-cmd --add-port 3128/tcp --permanent
Now the time to test out our proxy, in a different machine. This test machine does not have any internet connection to the outside world, except network connection to our proxy server.
First we use curl to try to reach ipecho.net/plain without proxy
$ curl ipecho.net/plain
curl: (6) Could not resolve host: ipecho.net
Next we will use curl with our brand new proxy. We can see that our machine is able to reach ipecho.net/plain, with the help of the proxy.
$ curl --proxy http://10.0.0.10:3128 ipecho.net/plain
210.210.210.210
Nice, happy proxying.
Saturday, November 7, 2020
Set static IP address in ubuntu 18.04
Thursday, November 5, 2020
Using rsync without ssh
Recently I have encountered a situation whereby I need to transfer a file to a server, and ssh client and server are not installed in that server. And to make matters worst, that server does not have internet connection for me to install openssh-clients on it. Luckily, that server has rsync installed, which kind of save my day.
What I will show here, is how to transfer file using rsync protocol without ssh. We will call the server without ssh, and without internet connectivity with serverA, and the other server that has internet connectivity as serverB.
serverA: server without ssh and internet connectivity
serverB: server with internet connectivity
After I have acquired all the files needed by serverA by downloading in serverB, I need to start rsync in daemon mode. Before that, I need to tell rsync which folder that I wish to share via the rsync protocol, by editing /etc/rsyncd.conf. Let's say I want to share my /tmp directory, which contain a file called myfile.txt.
serverB # cat >> /etc/rsyncd.conf <<EOF
[tmp]
path = /tmp
EOF
Next, start rsync in daemon mode. Rsync will make use of the /etc/rsyncd.conf for the daemon configuration.
serverB # rsync --daemon
We can see that rsync by default will listen on port 873
serverB # ss -tulpn | grep rsync
tcp LISTEN 0 128 0.0.0.0:873 0.0.0.0:*
In serverA, we need to use the rsync command to connect to rsync daemon in serverB. To check which directory is available for download:
serverA # rsync serverB::
tmp
Download the file
serverA # rsync serverB::tmp/myfile.txt
serverA # ls
myfile.txt
You have now downloaded the myfile.txt file, from serverB just by using rsync. A note to remember, rsync protocol does not have any encryption, but it is good enough for a LAN environment.
Download rpm installer file for already installed packages
If you have not install the packages, you can always use --downloadonly flag to just download the packages without installing. For example, I want to download rpm file for curl
# yum install --downloadonly curl
The file and its dependencies will be saved into /var/cache/yum.
But if you have installed the package, the above command will only return a message saying that "Packages is already installed, and nothing to do."
In order to download rpm file of an installed package with dependencies, another command is needed, which is repotrack, that is a command in yum-utils package.
First, install yum-utils
# yum install -y yum-utils
Then, run repotrack on the package that you need the rpm installer
# repotrack curl
All the packages will be downloaded to the current directory. Nice!
Wednesday, November 4, 2020
Minio on podman failed to run due to wrong selinux tag
I tried to install minio on podman, following this guide.
I created a directory for data
# mkdir /data
I then start minio container
# podman run -dit -p 9000:9000 -e "MINIO_ACCESS_KEY=minioadmin" -e "MINIO_SECRET_KEY=myminioadmin" -v /data:/data minio/minio server /data
The container was started, but exited as soon as it finished starting up
# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES