{"id":89,"date":"2022-04-10T11:37:49","date_gmt":"2022-04-10T09:37:49","guid":{"rendered":"https:\/\/blubb.fish\/?p=89"},"modified":"2022-04-10T11:37:50","modified_gmt":"2022-04-10T09:37:50","slug":"matrix-chat-server","status":"publish","type":"post","link":"https:\/\/blubb.fish\/index.php\/2022\/04\/10\/matrix-chat-server\/","title":{"rendered":"Matrix Chat Server"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In days where governments are checking out more and more services and demanding backdoors in messanger services it may be good to host his own messenger service.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I recently found this one and it seems to be quite easy to setup. All Information can also be found on the projects page<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Git Hub Project: https:\/\/github.com\/spantaleev\/matrix-docker-ansible-deploy<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not all the DNS Entries are needed. For messenger only setup only the matrix, element and the _SRV one are needed. we will do them all.<\/p>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">needed Ports:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Port<\/th><th>Protocol<\/th><th>Usage<\/th><\/tr><\/thead><tbody><tr><td>80<\/td><td>tcp<\/td><td>HTTP Webserver<\/td><\/tr><tr><td>443<\/td><td>tcp<\/td><td>HTTPs Webserver<\/td><\/tr><tr><td>3478<\/td><td>tcp<\/td><td>Turn<\/td><\/tr><tr><td>3478<\/td><td>udp<\/td><td>Turn<\/td><\/tr><tr><td>5349<\/td><td>tcp<\/td><td>Turn<\/td><\/tr><tr><td>5349<\/td><td>udp<\/td><td>Turn<\/td><\/tr><tr><td>8448<\/td><td>tcp<\/td><td>Matrix Federation<\/td><\/tr><tr><td>49152-49172<\/td><td>udp<\/td><td>Turn<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">needed DNS Entries:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">host must be set according to your DNS provider. some only need &lt;entry&gt; others want &lt;entry.domain.toplevel&gt;<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Type<\/td><td>host<\/td><td>Priority<\/td><td>weight<\/td><td>port<\/td><td>target<\/td><\/tr><tr><td>A<\/td><td>matrix<\/td><td><\/td><td><\/td><td><\/td><td>&lt;your-server-ip&gt;<\/td><\/tr><tr><td>SRV<\/td><td>_matrix-identity._tcp<\/td><td>10<\/td><td>0<\/td><td>443<\/td><td>&lt;matrix.your-domain.top<\/td><\/tr><tr><td>CNAME<\/td><td>element<\/td><td><\/td><td><\/td><td><\/td><td>&lt;matrix.your-domain.top<\/td><\/tr><tr><td>CNAME<\/td><td>dimension<\/td><td><\/td><td><\/td><td><\/td><td>&lt;matrix.your-domain.top<\/td><\/tr><tr><td>CNAME<\/td><td>jitsi<\/td><td><\/td><td><\/td><td><\/td><td>&lt;matrix.your-domain.top<\/td><\/tr><tr><td>CNAME<\/td><td>stats<\/td><td><\/td><td><\/td><td><\/td><td>&lt;matrix.your-domain.top<\/td><\/tr><tr><td>CNAME<\/td><td>goneb<\/td><td><\/td><td><\/td><td><\/td><td>&lt;matrix.your-domain.top<\/td><\/tr><tr><td>CNAME<\/td><td>sygnal<\/td><td><\/td><td><\/td><td><\/td><td>&lt;matrix.your-domain.top<\/td><\/tr><tr><td>CNAME<\/td><td>hydrogen<\/td><td><\/td><td><\/td><td><\/td><td>&lt;matrix.your-domain.top<\/td><\/tr><tr><td>CNAME<\/td><td>cinny<\/td><td><\/td><td><\/td><td><\/td><td>&lt;matrix.your-domain.top<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"has-x-large-font-size wp-block-paragraph\">Setup:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will run the install on an debian 11 Server. Playbooks don&#8217;t need to be on the Server. the can be run from an remote machine. that is the suggested way to do. so no config files with cleartext password will reside on the server. In our example we will run everything on one Server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">the installation is by default configured to run with root. this can be changed.<br>documented <a href=\"https:\/\/github.com\/spantaleev\/matrix-docker-ansible-deploy\/blob\/master\/docs\/installing.md\" data-type=\"URL\" data-id=\"https:\/\/github.com\/spantaleev\/matrix-docker-ansible-deploy\/blob\/master\/docs\/installing.md\">here<\/a>.<\/p>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">install prerequisites<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt upgrade\nsudo apt install python3 ansible pwgen<\/code><\/pre>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">Setup root user access with key:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">generate key with user root:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo -i\n$ ssh-keygen\nGenerating public\/private rsa key pair.\nEnter file in which to save the key (\/root\/.ssh\/id_rsa): \nCreated directory '\/root\/.ssh'.\nEnter passphrase (empty for no passphrase): \nEnter same passphrase again: \nYour identification has been saved in \/root\/.ssh\/id_rsa\nYour public key has been saved in \/root\/.ssh\/id_rsa.pub\nThe key fingerprint is:\nSHA256:9dzYvTU5smYvNYsigW+FKpYEiY\/cWAc1Ck3w9o5SNBU matrix@VM-e640e2b1-6de2-43ca-926d-700e69ba4604\nThe key's randomart image is:\n+---&#91;RSA 3072]----+\n| o+..E.          |\n|  ooo .          |\n|  .*o     .      |\n| .o+o.   . o + ..|\n|. *.o.  S . +.o+o|\n| +.oo. . o .  oo=|\n| . .... o o  +o.o|\n|  .  + . + .oo.. |\n|    . . . . . .. |\n+----&#91;SHA256]-----+\n\n# now we need to add the public key to the authorized_keys file\n$ cat \/root\/.ssh\/id_rsa.pub &gt;&gt; \/root\/.ssh\/authorized_keys<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we are able to ssh from root into root with ssh key auth<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">Clone git repository<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git clone https:\/\/github.com\/spantaleev\/matrix-docker-ansible-deploy.git<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">make configs<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">change to git directory<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cd matrix-docker-ansible-deploy\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">make directory for your configs<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ mkdir inventory\/host_vars\/matrix.&lt;your-domain&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">copy example configs to edit<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cp examples\/vars.yml inventory\/host_vars \/matrix.teichert.sh\/vars.yml\n$ cp examples\/hosts inventory\/hosts<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we generate two Passwords. one as the matrix server secret key which is used to encrypt other stuff in matrix. and one as postgres password<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will use pwgen for this<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">-s -&gt; secure. generates a totally random password (thats what the man page says ;))<br>64 -&gt; length of password<br>2 -&gt; how many to generate<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># generate matrix and postgres secret\n$ pwgen -s 64 2\nL0KYiXz2IYpaWNHQxwSEZLOvGiMTIo7ELRwtKGoyVpuvPXCAC7MXeIbAABr0wR61\nvXeNlsnaolAKEramzgXHFfJM8cIo3YTQ4XWreTVhQJSJM1Tqp633CTfZKc7ShNM0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">now we edit the vars.yml config file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># open file for writing\n$ vim inventory\/host_vars\/matrix.&lt;your-domain&gt;\/vars.yml<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Edit the config as following<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---\n# The bare domain name which represents your Matrix identity.\n# Matrix user ids for your server will be of the form (`@user:&lt;matrix-domain&gt;`).\n#\n# Note: this playbook does not touch the server referenced here.\n# Installation happens on another server (\"matrix.&lt;matrix-domain&gt;\").\n#\n# If you've deployed using the wrong domain, you'll have to run the Uninstalling step,\n# because you can't change the Domain after deployment.\n#\n# Example value: example.com\nmatrix_domain: &lt;your-domain&gt;\n\n# The Matrix homeserver software to install.\n# See `roles\/matrix-base\/defaults\/main.yml` for valid options.\nmatrix_homeserver_implementation: synapse\n\n# A secret used as a base, for generating various other secrets.\n# You can put any string here, but generating a strong one is preferred (e.g. `pwgen -s 64 1`).\nmatrix_homeserver_generic_secret_key: 'L0KYiXz2IYpaWNHQxwSEZLOvGiMTIo7ELRwtKGoyVpuvPXCAC7MXeIbAABr0wR61'\n\n# This is something which is provided to Let's Encrypt when retrieving SSL certificates for domains.\n#\n# In case SSL renewal fails at some point, you'll also get an email notification there.\n#\n# If you decide to use another method for managing SSL certificates (different than the default Let's Encrypt),\n# you won't be required to define this variable (see `docs\/configuring-playbook-ssl-certificates.md`).\n#\n# Example value: someone@example.com\nmatrix_ssl_lets_encrypt_support_email: '&lt;your-mail-address&gt;'\n\n# A Postgres password to use for the superuser Postgres user (called `matrix` by default).\n#\n# The playbook creates additional Postgres users and databases (one for each enabled service)\n# using this superuser account.\nmatrix_postgres_connection_password: 'vXeNlsnaolAKEramzgXHFfJM8cIo3YTQ4XWreTVhQJSJM1Tqp633CTfZKc7ShNM0'\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now we need to edit the hosts file. so it fits our setup.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim inventory\/hosts<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Edit the string to look as following<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># We explicitly ask for your server's external IP address, because the same value is used for configuring Coturn.\n# If you'd rather use a local IP here, make sure to set up `matrix_coturn_turn_external_ip_address`.\n#\n# To connect using a non-root user (and elevate to root with sudo later),\n# replace `ansible_ssh_user=root` with something like this: `ansible_ssh_user=username become=true become_user=root`\n#\n# For improved Ansible performance, SSH pipelining is enabled by default in `ansible.cfg`.\n# If this causes SSH connection troubles, disable it by adding `ansible_ssh_pipelining=False`\n# to the host line below or by adding `ansible_ssh_pipelining: False` to your variables file.\n#\n# If you're running this Ansible playbook on the same server as the one you're installing to,\n# consider adding an additional `ansible_connection=local` argument to the host line below.\n#\n# Ansible may fail to discover which Python interpreter to use on the host for some distros (like Ubuntu 20.04).\n# You may sometimes need to explicitly add the argument `ansible_python_interpreter=\/usr\/bin\/python3`\n# to the host line below.\n\n&#91;matrix_servers]\nmatrix.&lt;your-domain&gt; ansible_host=&lt;external-ip-address&gt; ansible_ssh_user=root<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now everything is ready for install the the application. The cool thing about ansible is that the playbooks are idempotent and can be run again and again and will only change what was changes<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible-playbook -i inventory\/hosts setup.yml --tags=setup-all<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">now all the playbooks will run for 5 &#8211; 10 minutes and none should show failed at the recap.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PLAY RECAP ******************************************************************************************************************************************************************\nmatrix.&lt;your-domain&gt;         : ok=221  changed=5    unreachable=0    failed=0    skipped=1696 rescued=0    ignored=0   \n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Start all services<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible-playbook -i inventory\/hosts setup.yml --tags=start<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">check the recap. nothiing should fail<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PLAY RECAP ******************************************************************************************************************************************************************\nmatrix.&lt;your-domain&gt;         : ok=22   changed=2    unreachable=0    failed=0    skipped=193  rescued=0    ignored=0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now the Server is up and running. user registration is by default disabled.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">we can access https:\/\/element.&lt;your-domain&gt; to verify if everything looks good. Element is the Web Interface for matrix.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"397\" src=\"https:\/\/blubb.fish\/wp-content\/uploads\/2022\/03\/element-1024x397.png\" alt=\"\" class=\"wp-image-92\" srcset=\"https:\/\/blubb.fish\/wp-content\/uploads\/2022\/03\/element-1024x397.png 1024w, https:\/\/blubb.fish\/wp-content\/uploads\/2022\/03\/element-300x116.png 300w, https:\/\/blubb.fish\/wp-content\/uploads\/2022\/03\/element-768x297.png 768w, https:\/\/blubb.fish\/wp-content\/uploads\/2022\/03\/element.png 1361w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">now we need to create a user for login<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are two ways to create a user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use ansible or via CLI on the Server<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible-playbook -i inventory\/hosts setup.yml --extra-vars='username=&lt;your-username&gt; password=&lt;your-password&gt; admin=&lt;yes|no&gt;' --tags=register-user<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>OR<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/local\/bin\/matrix-synapse-register-user &lt;your-username&gt; &lt;your-password&gt; &lt;admin access: 0 or 1&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we should be able to login with the user in the element UI.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default the setup federates with the whole matrix network.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To disable this add the following to inventory\/host_vars\/matrix.\/vars.yml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>matrix_synapse_federation_enabled: false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To share your public rooms to the whole matrix network add the following to inventory\/host_vars\/matrix.\/vars.yml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>matrix_synapse_allow_public_rooms_over_federation: true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">in either case you have to rerun the install routine<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible-playbook -i inventory\/hosts setup.yml --tags=setup-all<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Gratulations. Your own messaging server is now up and running and can be used for messaging in browser and mobile app.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">more articles about the other functions will follow.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In days where governments are checking out more and more services and demanding backdoors in messanger services it may be good to host his own messenger service. I recently found this one and it seems to be quite easy to setup. All Information can also be found on the projects page Git Hub Project: https:\/\/github.com\/spantaleev\/matrix-docker-ansible-deploy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3,10],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-anonymity","category-linux","category-matrix"],"_links":{"self":[{"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":7,"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":117,"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions\/117"}],"wp:attachment":[{"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blubb.fish\/index.php\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}