Matrix. An open network for secure and decentralized communication that you can install in your Ubuntu server

How to Manage Decentralized Communication Esily and in RealTime

by Luigi Nori Date: 25-08-2020 matrix decentralized server

Imagine to have an open platform that is as independent, vibrant and evolving as the Web itself, but for communication. As of June 2019, Matrix is out of beta, and the protocol is fully suitable for production usage. But, what is Matrix? Matrix is an open standard for real-time, interoperable and decentralized communication over IP, used to power VoIP/WebRTC signalling, Internet of Things communication, Instant Messaging, and every program that requires a standard HTTP API for publishing and subscribing to data whilst tracking the conversation history.  

matrix It’s interoperable, meaning it is designed to interoperate with other communication systems, and being an Open Standard means it’s easy to see how to interoperate with it. Also, it is decentralized, which means there is no central point – anyone can host their own server and have control over their data and it is designed to function in real-time, which means it is ideal for building systems that require the immediate exchange of data, such as Instant Messaging.

Developed as an open initiative with no company behind it, its “longer term goal is for Matrix to act as a generic HTTP messaging and data synchronization system for the whole web – allowing people, services and devices to easily communicate with each other, empowering users to own and control their data and select the services and vendors they want to use”.

Besides being a standard, Matrix provides many features:

  • Open Standard HTTP APIs for transferring JSON messages (e.g. instant messages, WebRTC signalling)
  • Client<->Server API defining how Matrix compatible clients communicate with Matrix home servers.
  • Server<->Server API defining how Matrix home servers exchange messages and synchronize history with each other.
  • Application Service API defining how to extend the functionality of Matrix with ‘integrations’ and bridge to other networks.
  • Modules specifying features that must be implemented by particular classes of clients.
  • Open source reference implementations of clients, client SDKs, home serves and application services.

So Matrix could be a better way of communication system, but also a better and secure web, respectful of privacy.

To connect to the Matrix federation, you have to use a client. You can find the most popular Matrix clients available today at the matrix-clients page, and more are available at try-matrix-now. To get started using Matrix, pick a client and join #matrix:matrix.org room.

To start to be in the Matrix quicker, you can use the web client Riot. Go to riot.im/app to get started – this will allow you to sign up for a new account on Matrix.org, and get chatting right away. There are also native Riot apps for Android and iOS.

We mentioned home servers: they are what store account information and communication history, sharing data with the wider Matrix ecosystem by synchronizing the communication history with other home servers.

This tutorial is about the installation of Synapse, the reference home server implementation of Matrix.

Install Matrix in your Ubuntu

Matrix provides a repository for Ubuntu, so that installations can be handled through apt.

Add Matrix Repository

First of all, add the repository key:

$ wget -qO - https://matrix.org/packages/debian/repo-key.asc | sudo apt-key add -

Add the official Matrix repository by executing:

# add-apt-repository https://matrix.org/packages/debian/

Update apt packages index:

# apt-get update

Install Matrix Synapse

Install Synapse with apt:

# apt-get install matrix-synapse

During the installation process, enter a domain name and choose whether or not to send statistics to Matrix.

Start and Enable Matrix

Start Matrix with systemctl

# systemctl start matrix-synapse

Enable it to start at boot time:

# systemctl enable matrix-synapse

Create a New User

Creating a new user for Matrix requires a shared secret. Generate a 32-character string that will be used as shared secret with:

# cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1

Copy the generated string, and then open the homeserver configuration file, /etc/matrix-synapse/homeserver.yaml, with a text editor:

# $EDITOR /etc/matrix-synapse/homeserver.yaml

In this file, look for registration_shared_secret. Uncomment that line and set its value as the 32-character string generated with the previous command:

# If set, allows registration by anyone who also has the shared
# secret, even if registration is otherwise disabled.
registration_shared_secret: "urandom_generated_string"

Save and close the file.

Restart Matrix Synapse with systemctl:

# systemctl restart matrix-synapse

Now it is possible to create a new Matrix user. Use the register_new_matrix_user command as follows:

$ register_new_matrix_user -c /etc/matrix-synapse/homeserver.yaml https://
localhost:8448

Configure NGINX for Matrix

Create a new virtual host file for the domain used by Matrix:

# nano /etc/nginx/sites-available/example.com

In this new file, paste the following content:

server {
    listen 80;
    listen [::]:80;

    root /var/www/html;
    index index.html index.htm;

    server_name example.com www.example.com;

    location /_matrix {
        proxy_pass http://localhost:8008;
    }

    location ~ /.well-known {
        allow all;
    }
}

The location block needs to be set up for _matrix, since this is where all Matrix clients send requests.

Enable this newly created configuration:

# ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com

Test it with:

# nginx -t

Its output should be a syntax OK one.

Conclusion

Matrix is the basis for many different clients that can be used to connect to the configured homeserver and decentralize communication systems. This tutorial has covered the most basic steps for obtaining and running a powerful server for decentralized communication backed by Ubuntu 16.04.

References:

 
by Luigi Nori Date: 25-08-2020 matrix decentralized server hits : 5819  
 
Luigi Nori

Luigi Nori

He has been working on the Internet since 1994 (practically a mummy), specializing in Web technologies makes his customers happy by juggling large scale and high availability applications, php and js frameworks, web design, data exchange, security, e-commerce, database and server administration, ethical hacking. He happily lives with @salvietta150x40, in his (little) free time he tries to tame a little wild dwarf with a passion for stars.

 
 
 

Related Posts

A collection of interesting networks and technology aiming at re-decentralizing the Internet

The decentralised web, or DWeb, could be a chance to take control of our data back from the big tech firms. So how does it work? Take a look at…

Clicky