Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

SSH Tutorial - How to access UNIX server from WINDOWS client

Hello Buddies.

Here is a quick tutorial to get hands-on experience in accessing a remote machine.
It can either be a case of a remote machine being used as a server or as a storage location.

In case your remote machine is having Windows platform, things become really straightforward. Just need to use MSTSC – Remote login through your windows machine, enter the credentials, and boom, you are already on the remote machine!

Complications occur when the remote machine is UNIX based.

For the same, this tutorial will be based on the below scenarios –

  • Remote machine: UNIX based – here it’s Fedora
    • Remote machine will be hosting a simple HTML page
    • It will be using Apache HTTPD as the server
    • To enable access, it will use SSH
  • Client machine: Windows-based
    • It will use putty for SSH access
    • It will also update the HTML content of the remote server


Sounds interesting?
 Cool! Let’s begin the discussion.


All About Remote

Using Apache HTTP Server project here.

Install:         sudo dnf install httpd
Start:           sudo systemctl start httpd.service
Check:        using http://localhost.

The root directory of your web server is now situated at /var/www/html/ with root as the owner.

Comment out all the lines in /etc/httpd/conf.d/welcome.conf default page landing. 

Create an index.html file with your content in the /var/www/html/ directory:

<html>
    <head>
        <title>Hello world</title>
    </head>
    <body>
        Hello world!
    </body>
</html>

Now, when you visit http://localhost, you will see your new index page.

Yeah! It looks cool! Changes are picked up nicely and easily!


Can I access this web page from any other machine?


Here comes a tricky part. By default, each OS has restrictions over ports, and firewalls as well.
So, you need to, first of all, find the public IP of your system and allow access to a port that would be exposed.









In a UNIX machine, you can check the iptables, for the status of the ports.

  iptables -L

Also open the port 80, for the apache server.

  iptables -I INPUT -p tcp --dport 80 -j ACCEPT

For the IP address of the machine, use ifconfig.

Boom!

Hit the URL from any machine now – http://192.168.xx.xx:80

And you will see the content !!!





 







What if I want to change the content from my client machine?


Here comes another tricky part, that surely demands at least one hands-on experience.

  • Get openssh-server on your server machine 
    •  sudo dnf install openssh-server






  • Start the ssh service
    • sudo systemctl start sshd.service
  • By default, it will use port 22. Remember this!
  • Also, doing some authentication stuff here.
    • Use keygen command to generate an RSA private key at the server side.
    •  # ssh-keygen -t dsa
  • Save the key, for now, bypass the passphrase as empty.


Use the saved private key in your windows client now. How? 
Check this below!

  • Install putty in your windows client.
  • Open puttyGen.
  • Load the imported private key.
  • Open putty, enter the IP address of the server machine.
  • Remember the default port number? Yes, correct. It should be 22.


Hit it. Boom! You are in the server machine now.

Remember where your HTML content was being picked up from?
Yup, correct!

Update the content at /var/www/html/ 


















Refresh the web pages, and you will have new content with you.




















So, this was a quick one! Keep exploring.

And Happy coding!










WSO2 ESB - HELLO WORLD - CLASS MEDIATION

WSO2 - ESB

 I came across this thing recently, and generally as we developers do, I did some head banging.
Assuming that theory is not what you are looking for, this post will land you in the arena directly, with working demo, following the old school tradition - a 'Hello World' program 🙂.

This will be involving ESB 5.x.x, based on the online documentation it is too easy to proceed with the installation part, Fedora 24 or any other yummy UNIX flavor.

I suggest you to install ESB bundle with Eclipse Luna from the site, since the latest version available i.e. the one with Eclipse Mars, will throw lot of NPEs in the environment.






package abc;

import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;

public class MedTester extends AbstractMediator {

    public boolean mediate(MessageContext context) {
        // TODO Implement your mediation logic here
        System.out.println("Wassup ??????? ");
        return true;
    }
}

Steps to follow ahead -


Upload the jar for the above class in wso2esb-5.x.x/repository/components/lib folder.

Start the analytics server then your core server.

Add a sequence with class mediator.

Make sure class is uploaded successfully.


Create an API for invoking your above sequence.


Hit the below url using curl command -

http://172.16.2.34:8280/helloContext/helloAPI

curl -X GET http://172.16.2.34:8280/helloContext/helloAPI/





Here you go! Enjoy the output. 🙂



Featured post

Oracle SQL Scheduled Jobs - An Interesting Approach

  Oracle SQL Scheduled Jobs A DB Scheduler is the best way to automate any backend database job. For instance, if you want to process the p...