<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[A Sys Admin's Journey]]></title><description><![CDATA[A Sys Admin's Struggle]]></description><link>https://joe-lance.com/</link><image><url>https://joe-lance.com/favicon.png</url><title>A Sys Admin&apos;s Journey</title><link>https://joe-lance.com/</link></image><generator>Ghost 5.63</generator><lastBuildDate>Mon, 04 May 2026 16:09:50 GMT</lastBuildDate><atom:link href="https://joe-lance.com/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Listening to a message broker with php]]></title><description><![CDATA[<h1 id="integrating-php-with-message-brokers-an-actionable-guide">Integrating PHP with Message Brokers: An Actionable Guide</h1><p>In the world of distributed systems and microservices, message brokers have become an integral component. They facilitate communication between different parts of a system, ensuring data gets where it needs to go. PHP, as a popular backend language, can be integrated with</p>]]></description><link>https://joe-lance.com/listening-to-a-message-broker-with-php/</link><guid isPermaLink="false">6509d973f446acf5ea468be4</guid><dc:creator><![CDATA[Joe Lance]]></dc:creator><pubDate>Tue, 19 Sep 2023 17:25:20 GMT</pubDate><media:content url="https://joe-lance.com/content/images/2023/09/radioicon.png" medium="image"/><content:encoded><![CDATA[<h1 id="integrating-php-with-message-brokers-an-actionable-guide">Integrating PHP with Message Brokers: An Actionable Guide</h1><img src="https://joe-lance.com/content/images/2023/09/radioicon.png" alt="Listening to a message broker with php"><p>In the world of distributed systems and microservices, message brokers have become an integral component. They facilitate communication between different parts of a system, ensuring data gets where it needs to go. PHP, as a popular backend language, can be integrated with message brokers to listen to messages and perform actions based on them. In this blog post, we&apos;ll explore how to do just that.</p><h2 id="what-is-a-message-broker">What is a Message Broker?</h2><p>A message broker acts as an intermediary for messaging between different parts of a system. It can receive messages from a producer service, store them, and deliver them to consumer services when appropriate. Examples include RabbitMQ, Apache Kafka, and ActiveMQ.</p><h2 id="why-integrate-php-with-a-message-broker">Why integrate PHP with a Message Broker?</h2><p>Imagine you have an e-commerce website built using PHP. When a user places an order, you might want to notify multiple services - billing, shipping, and inventory, for example. A message broker can distribute this message to all these services, ensuring no service is overwhelmed with direct requests.</p><h2 id="listening-to-a-message-broker-with-php-a-rabbitmq-example">Listening to a Message Broker with PHP: A RabbitMQ Example</h2><p>For this guide, we&apos;ll use RabbitMQ, a widely-used open-source message broker, and the PHP AMQP library.</p><h3 id="prerequisites">Prerequisites</h3><ol><li>A running instance of RabbitMQ. You can install it following the <a href="https://www.rabbitmq.com/download.html?ref=joe-lance.com">official guide</a>.</li><li>PHP and Composer installed.</li></ol><h3 id="steps">Steps:</h3><h4 id="1-install-the-php-amqp-library">1. Install the PHP AMQP Library:</h4><p>Using Composer, install the <code>php-amqplib/php-amqplib</code> package:</p><pre><code class="language-bash">composer require php-amqplib/php-amqplib
</code></pre><h4 id="2-set-up-connection">2. Set up Connection:</h4><p>Create a new PHP script and set up a connection to RabbitMQ:</p><pre><code class="language-php">&lt;?php
require_once __DIR__ . &apos;/vendor/autoload.php&apos;;

use PhpAmqpLib\Connection\AMQPStreamConnection;

$connection = new AMQPStreamConnection(&apos;localhost&apos;, 5672, &apos;guest&apos;, &apos;guest&apos;);
$channel = $connection-&gt;channel();
</code></pre><p>Here, we&apos;re connecting to a local RabbitMQ instance with the default credentials.</p><h4 id="3-declare-a-queue">3. Declare a Queue:</h4><p>Before we can listen to messages, we need to declare a queue:</p><pre><code class="language-php">$queueName = &apos;test_queue&apos;;
$channel-&gt;queue_declare($queueName, false, false, false, false);
</code></pre><h4 id="4-listen-to-messages-and-perform-action">4. Listen to Messages and Perform Action:</h4><p>Now, let&apos;s listen to messages and print them out:</p><pre><code class="language-php">echo &quot;Waiting for messages. To exit press CTRL+C\n&quot;;

$callback = function ($msg) {
    echo &apos;Received: &apos;, $msg-&gt;body, &quot;\n&quot;;
    // Here, you can perform any action based on the message content.
    // For instance, sending an email, updating a database, etc.
};

$channel-&gt;basic_consume($queueName, &apos;&apos;, false, true, false, false, $callback);

while ($channel-&gt;is_consuming()) {
    $channel-&gt;wait();
}
</code></pre><p>Run your PHP script, and it will start listening to messages sent to the &apos;test_queue&apos; queue. Whenever a message is received, it will print it out and perform any defined actions within the callback.</p><h4 id="5-cleanup">5. Cleanup:</h4><p>After you&apos;re done, it&apos;s essential to close the channel and connection:</p><pre><code class="language-php">$channel-&gt;close();
$connection-&gt;close();
</code></pre><h2 id="conclusion">Conclusion:</h2><p>Message brokers are a powerful way to decouple components in a distributed system. By integrating PHP with RabbitMQ, you can easily set up event-driven architectures where PHP services listen to messages and act on them. While we&apos;ve used RabbitMQ in this example, the principles are similar for other message brokers. Dive in, explore, and let your systems communicate seamlessly.</p>]]></content:encoded></item><item><title><![CDATA[Chrooted SFTP with auditing and remote sync]]></title><description><![CDATA[<h1 id="creating-a-chrooted-sftp-jail-a-step-by-step-guide">Creating a Chrooted SFTP Jail: A Step-by-Step Guide</h1><p>Secure File Transfer Protocol (SFTP) is often used for securely transferring files over a network. However, in certain scenarios, you may need to restrict users to specific directories, preventing them from wandering around the file system. This is where &quot;chroot jails&</p>]]></description><link>https://joe-lance.com/chrooted-sftp-with-auditing-and-remote-sync/</link><guid isPermaLink="false">6509714ef446acf5ea468bd8</guid><dc:creator><![CDATA[Joe Lance]]></dc:creator><pubDate>Tue, 19 Sep 2023 10:03:15 GMT</pubDate><media:content url="https://joe-lance.com/content/images/2023/09/bars.jpg" medium="image"/><content:encoded><![CDATA[<h1 id="creating-a-chrooted-sftp-jail-a-step-by-step-guide">Creating a Chrooted SFTP Jail: A Step-by-Step Guide</h1><img src="https://joe-lance.com/content/images/2023/09/bars.jpg" alt="Chrooted SFTP with auditing and remote sync"><p>Secure File Transfer Protocol (SFTP) is often used for securely transferring files over a network. However, in certain scenarios, you may need to restrict users to specific directories, preventing them from wandering around the file system. This is where &quot;chroot jails&quot; come in handy.</p><p>A chroot jail is essentially an isolated environment in which a user is restricted to a specific directory tree. In the context of SFTP, this can add an extra layer of security by limiting users&apos; activities to their designated folders.</p><p>In this blog post, we&apos;ll walk through the process of setting up a chrooted SFTP jail on a Linux server. I&apos;ll assume you have some basic knowledge of Linux command line, file permissions, and SSH/SFTP.</p><h2 id="prerequisites">Prerequisites</h2><ol><li>A Linux server with SSH enabled.</li><li>Root or sudo access to the server.</li></ol><h2 id="step-1-create-user-for-sftp">Step 1: Create User for SFTP</h2><p>First, let&apos;s create a new user who will be using SFTP.</p><pre><code class="language-bash">sudo adduser sftpuser
</code></pre><p>Follow the prompts to set a password and any other required information.</p><h2 id="step-2-create-directory-structure">Step 2: Create Directory Structure</h2><p>We need to create a directory structure that will act as the chroot environment for our SFTP user.</p><pre><code class="language-bash">sudo mkdir -p /sftp/sftpuser
sudo mkdir /sftp/sftpuser/files
</code></pre><p>The <code>/sftp/sftpuser</code> directory will be the chroot jail, and the <code>files</code> subdirectory will be where the user can upload files.</p><h2 id="step-3-set-permissions-and-ownership">Step 3: Set Permissions and Ownership</h2><p>Set the proper permissions and ownership for the chroot directory.</p><pre><code class="language-bash">sudo chown root:root /sftp/sftpuser
sudo chmod 755 /sftp/sftpuser
</code></pre><p>For the <code>files</code> subdirectory, you can assign ownership to the SFTP user:</p><pre><code class="language-bash">sudo chown sftpuser:sftpuser /sftp/sftpuser/files
</code></pre><h2 id="step-4-configure-sshd-for-chroot">Step 4: Configure SSHD for Chroot</h2><p>Open the SSH daemon configuration file for editing.</p><pre><code class="language-bash">sudo nano /etc/ssh/sshd_config
</code></pre><p>Append the following lines to the end of the file:</p><pre><code class="language-text">Match User sftpuser
    ChrootDirectory /sftp/sftpuser
    ForceCommand internal-sftp
    PasswordAuthentication yes
    AllowTcpForwarding no
</code></pre><p>Save and exit the editor.</p><h2 id="step-5-restart-sshd-service">Step 5: Restart SSHD Service</h2><p>Restart the SSH daemon to apply the changes.</p><pre><code class="language-bash">sudo systemctl restart sshd
</code></pre><h2 id="step-6-test-the-setup">Step 6: Test the Setup</h2><p>From a client machine, you can now try connecting via SFTP.</p><pre><code class="language-bash">sftp sftpuser@your_server_ip
</code></pre><p>You should be able to connect and be restricted to the <code>/files</code> directory.</p><h2 id="conclusion">Conclusion</h2><p>Setting up a chrooted SFTP jail is an effective way to restrict SFTP users to specific directory trees, enhancing the security of your server. This guide outlines the basic steps to set this up; however, further hardening and customization can be done based on your specific needs.</p><p>Always remember to thoroughly test any new configurations and to backup existing ones before making changes. Security is a continuously evolving discipline, and it is crucial to keep abreast of best practices to ensure your systems remain secure.</p>]]></content:encoded></item></channel></rss>