<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>debian Archives &#8226; Tech Jungle</title>
	<atom:link href="https://tech-jungle.com/tag/debian/feed/" rel="self" type="application/rss+xml" />
	<link>https://tech-jungle.com/tag/debian/</link>
	<description>Tech, Computers, and Programming</description>
	<lastBuildDate>Sat, 21 Jun 2025 17:57:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.5</generator>

<image>
	<url>https://tech-jungle.com/wp-content/uploads/2019/01/full-size-favicon-150x150.png</url>
	<title>debian Archives &#8226; Tech Jungle</title>
	<link>https://tech-jungle.com/tag/debian/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Login to Linux Machines using Active Directory (LDAP)</title>
		<link>https://tech-jungle.com/login-to-linux-machines-using-active-directory-ldap/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=login-to-linux-machines-using-active-directory-ldap</link>
					<comments>https://tech-jungle.com/login-to-linux-machines-using-active-directory-ldap/#respond</comments>
		
		<dc:creator><![CDATA[Bobby Gecko]]></dc:creator>
		<pubDate>Sat, 21 Jun 2025 17:48:17 +0000</pubDate>
				<category><![CDATA[Enterprise]]></category>
		<category><![CDATA[Linux-Related]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[domain controller]]></category>
		<category><![CDATA[kerberos]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[windows domain]]></category>
		<guid isPermaLink="false">https://tech-jungle.com/?p=323</guid>

					<description><![CDATA[<p>Despite its age, Active Directory does a pretty solid job of identity management. A lot of businesses still rely on it, and numerous third-party systems offer ways to integrate with it. While AD doesn&#8217;t do much for system management when it comes to Linux machines (unlike GPO&#8217;s for Windows), it&#8217;s<a class="moretag" href="https://tech-jungle.com/login-to-linux-machines-using-active-directory-ldap/"> Read more</a></p>
<p>The post <a href="https://tech-jungle.com/login-to-linux-machines-using-active-directory-ldap/">Login to Linux Machines using Active Directory (LDAP)</a> appeared first on <a href="https://tech-jungle.com">Tech Jungle</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Despite its age, Active Directory does a pretty solid job of identity management. A lot of businesses still rely on it, and numerous third-party systems offer ways to integrate with it.</p>



<p>While AD doesn&#8217;t do much for system management when it comes to Linux machines (unlike GPO&#8217;s for Windows), it&#8217;s still possible to leverage it&#8217;s identity management to consolidate credentials and permissions. A lot of operations that rely on Active Directory for Linux authentication usually tackle system management through specialized tools like Ansible or Mobile Device Management solutions.</p>



<p>Now that we&#8217;ve touched on the why (and if you&#8217;re reading this, it&#8217;s you probably already understand that part), let&#8217;s get to the how.</p>



<h2 class="wp-block-heading">Prerequisites</h2>



<p>To set up LDAP login on a Linux machine, we need to connect it to the domain. For that, the Linux machine must be pointed at authoritative domain DNS server(s) and also configured to search the correct  domain. That said, most Linux machines that are running an external DNS server won&#8217;t qualify unless they have multiple IPs or network adapters configured first (one for the internal domain and another for handling external DNS requests).</p>



<p>So let&#8217;s go through the process for setting up a Debian machine for LDAP authentication. The first config file of interest is the network configuration file.</p>



<pre class="wp-block-code"><code><code>nano /etc/network/interfaces</code></code></pre>



<p>The &#8220;dns-nameservers&#8221; option here should be pointed to the IP address (or addresses) of your domain&#8217;s DNS server(s). The &#8220;dns-search&#8221; option should also be set to the domain name, e.g. &#8220;mydomain.local&#8221;. After making the necessary changes, save and exit the file.</p>



<p>Now that we&#8217;ve updated our networking configuration, we&#8217;ll need to ensure our hosts file contains the FQDN of the local machine, and not just the hostname.</p>



<pre class="wp-block-code"><code>nano /etc/hosts</code></pre>



<p>Assuming our machine&#8217;s hostname is &#8220;linux-server&#8221;, and our domain is &#8220;mydomain.local&#8221; we&#8217;ll need to make sure that our host file appears like the following:</p>



<pre class="wp-block-code"><code>127.0.0.1 localhost
127.0.1.1 linux-server.mydomain.local linux-server</code></pre>



<p>Please note, we put the FQDN of our server before the hostname. Again, save and close the file.</p>



<h2 class="wp-block-heading">Install Required Packages</h2>



<p>As the root user or as a user with sudo privileges, run the following:</p>



<pre class="wp-block-code"><code>apt-get install realmd libnss-sss libpam-sss sssd sssd-tools adcli samba-common-bin oddjob oddjob-mkhomedir packagekit</code></pre>



<h2 class="wp-block-heading">Discover the Domain</h2>



<p>We can now utilize the &#8220;realm discover&#8221; command to evaluate the Active Directory domain. &#8220;Realm&#8221; is a command line utility that helps manage enrollment in Kerberos realms (such as Active Directory domains). The discover option enables the system to locate a realm/domain and its features. Executing the &#8220;realm discover&#8221; command should provide details about the domain and help identify the most suitable software stack to use with sssd.</p>



<p>realm discover i7media.local</p>



<p>The command should return info about the domain as well as what software packages are required to connect to it (though in our case, we&#8217;ve already installed them).</p>



<h2 class="wp-block-heading">Join the Domain</h2>



<p>The &#8220;realm join&#8221; command will join the current machine to the domain that we specify. To join the domain, we have to use a pre-existing domain account with join privileges. The command should look something like this:</p>



<p>realm join -U &lt;username&gt; mydomain.local</p>



<h2 class="wp-block-heading">Tuning the Setup</h2>



<p>While the default configuration will indeed allow for domain authenticated logins, there are a few things we can do to avoid annoyance later. Tuning the configuration benefits us in the following four ways:</p>



<ol class="wp-block-list">
<li>We want to avoid <em>sssd</em> related errors on boot (the errors do not affect the ability to login however they can be confusing) as outlined here &#8211; <a href="https://phabricator.wikimedia.org/T291585">https://phabricator.wikimedia.org/T291585</a></li>



<li>We will streamline the login process (by default, accounts have to use the full FQDN when logging in and not just the username).</li>



<li>We can restrict logins to only members of certain Active Directory groups (regular office staff normally don&#8217;t need to login to servers)</li>



<li>We will address an issue that can cause intermittent login failures (this issue may be fixed in future releases so it is a good idea to check periodically)</li>
</ol>



<p>All of these configuration changes can be made by editing the &#8220;/etc/sssd/sssd.conf&#8221; file in your editor of choice. After editing, the result should look like the following:</p>



<pre class="wp-block-code"><code>&#91;sssd]
domains = mydomain.local
config_file_version = 2


&#91;domain/mydomain.local]
default_shell = /bin/bash
krb5_store_password_if_offline = True
cache_credentials = True
krb5_realm = MYDOMAIN.LOCAL
realmd_tags = manages-system joined-with-adcli
id_provider = ad
fallback_homedir = /home/%u@%d
ad_domain = MYDOMAIN.LOCAL
use_fully_qualified_names = False
ldap_id_mapping = True
access_provider = simple
simple_allow_groups = Domain Admins@mydomain.local
ad_gpo_access_control = permissive</code></pre>



<p>You can find a list of configuration options in the man page for SSSD, while the configuration above is all most people will need, you can find said page at the link below:</p>



<p><a href="https://linux.die.net/man/5/sssd.conf">https://linux.die.net/man/5/sssd.conf</a></p>



<p>After making your changes, save and close the file and then restart the sssd service:</p>



<p>service sssd restart</p>



<h2 class="wp-block-heading">Create Home Directory for Accounts on Logon</h2>



<p>Typically when domain users log in they don&#8217;t get their own home directory. However, we can configure it so that these home directories are created automatically upon login via the following:</p>



<pre class="wp-block-code"><code>pam-auth-update --enable mkhomedir</code></pre>



<h2 class="wp-block-heading">Test Logon with Domain Account</h2>



<p>You can now test domain login by using the &#8220;login&#8221; command along with the domain user&#8217;s credentials. If all goes well, you should be able to log in as that user without any issues.</p>



<h2 class="wp-block-heading">Install and Configure sudo</h2>



<p>It&#8217;s awesome to authenticate using a domain account, but to perform admin tasks on the machine, we need to make sure the right accounts have sudo privileges. The typical Debian server setup doesn&#8217;t have  sudo pre-installed, so we&#8217;ll have to install it first.</p>



<pre class="wp-block-code"><code>apt-get install sudo</code></pre>



<p>Next we&#8217;ll need to add the desired Active Directory group to a <em>sudo</em> config file so users will be allowed to run commands as root. In our example above, we configured LDAP login for the &#8220;Domain Admins&#8221; group so in keeping with that example we will name the <em>sudo</em> config file accordingly:</p>



<pre class="wp-block-code"><code>nano /etc/sudoers.d/domain_admins</code></pre>



<p>Then inside of that new file we will specify the group:</p>



<pre class="wp-block-code"><code>"%domain admins"    ALL=(ALL:ALL) ALL</code></pre>



<p>Note that because there is a space in the group name we have to use quotation marks. After saving and closing the file, you should be able to login and run <em>sudo</em> with any user in the &#8220;Domain Admins&#8221; group.</p>



<h2 class="wp-block-heading">Add Users to the Linux ADM Group</h2>



<p>Although we&#8217;ve already given our domain administrators supercow powers via sudo, there might be certain tasks that require the user to be a member of the &#8220;adm&#8221; group (like accessing system logs). No worries, though, this is pretty straightforward. Once you&#8217;re logged in, just execute the following command:</p>



<pre class="wp-block-code"><code>sudo usermod -aG adm &lt;username&gt;</code></pre>



<p>After logging out and then back in again (assuming you are adding the current account being used into said group) your account will have admin group access on the machine.</p>



<h2 class="wp-block-heading">Final Notes</h2>



<p>If this writeup has saved you some time or annoyance consider leaving a greeting in the comments section. I&#8217;m always happy to help with technical questions anyway I can. <img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a href="https://tech-jungle.com/login-to-linux-machines-using-active-directory-ldap/">Login to Linux Machines using Active Directory (LDAP)</a> appeared first on <a href="https://tech-jungle.com">Tech Jungle</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tech-jungle.com/login-to-linux-machines-using-active-directory-ldap/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Properly Setting up Nextcloud 21 on Debian 10 (Buster)</title>
		<link>https://tech-jungle.com/properly-setting-up-nextcloud-21-on-debian-10-buster/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=properly-setting-up-nextcloud-21-on-debian-10-buster</link>
					<comments>https://tech-jungle.com/properly-setting-up-nextcloud-21-on-debian-10-buster/#comments</comments>
		
		<dc:creator><![CDATA[Bobby Gecko]]></dc:creator>
		<pubDate>Fri, 04 Jun 2021 10:16:54 +0000</pubDate>
				<category><![CDATA[Enterprise]]></category>
		<category><![CDATA[Linux-Related]]></category>
		<category><![CDATA[apcu]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[certbot]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[nextcloud]]></category>
		<guid isPermaLink="false">https://tech-jungle.com/?p=286</guid>

					<description><![CDATA[<p>There are other articles out there that can give you a basic setup, however this is how I would recommend properly setting up Nextcloud 21 on Debian 10 (Buster). Why the &#8220;properly&#8221; qualifier? Well because many of the other articles I&#8217;ve read will get you to the point of a<a class="moretag" href="https://tech-jungle.com/properly-setting-up-nextcloud-21-on-debian-10-buster/"> Read more</a></p>
<p>The post <a href="https://tech-jungle.com/properly-setting-up-nextcloud-21-on-debian-10-buster/">Properly Setting up Nextcloud 21 on Debian 10 (Buster)</a> appeared first on <a href="https://tech-jungle.com">Tech Jungle</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>There are other articles out there that can give you a basic setup, however this is how I would recommend properly setting up <a href="https://nextcloud.com/">Nextcloud</a> 21 on <a href="https://www.debian.org/">Debian</a> 10 (Buster).</p>



<p>Why the &#8220;properly&#8221; qualifier? Well because many of the other articles I&#8217;ve read will get you to the point of a working Nextcloud 21 install on Debian Buster &#8211; but not one that I would consider what an actual deployment should be. </p>



<p>To confound the problem, Nextcloud&#8217;s own documentation might say e.g &#8220;you should set up caching services for best performance&#8221; but it doesn&#8217;t really offer a step-by-step guide on how to do that. How about previews for PDF files and Movies? That&#8217;s probably not even something you knew was an option (either because you assumed it would come enabled out of the box, or because you didn&#8217;t know it was possible). So we&#8217;ll start with the core setup, and finish with the bells and whistles.</p>



<h2 class="wp-block-heading">Prerequisites</h2>



<p>While Nextcloud has published the <a href="https://docs.nextcloud.com/server/latest/admin_manual/installation/system_requirements.html">system requirements</a> on their site &#8211; the numbers there are (in my opinion) more geared towards a home setup, with only a handful of people using the service. It&#8217;s worth pointing out that they offer <a href="https://nextcloud.com/enterprise/">enterprise support</a> for a reason &#8211; so if you&#8217;re approaching this project on behalf of an organization, it may be wise to  consider whether or not you might be better served by an enterprise license. </p>



<p>As far as minimum hardware recommendations go, for this setup here&#8217;s what I&#8217;d recommend:</p>



<p><strong>Host:</strong></p>



<ul class="wp-block-list"><li>2 CPU Cores</li><li>2GB of RAM</li><li>1 storage device for Debian OS</li><li>1 separate storage device for Nextcloud data</li></ul>



<p>If you&#8217;re planning on setting up Nextcloud to be accessible over the WAN (we will cover that in this article) I would strongly recommend that you have a static public IP AND (if at all possible) a firewall on your network that has a good  <a href="https://www.juniper.net/us/en/products-services/what-is/ids-ips/">IDS/IPS system</a>. While the developers for Nextcloud have put a lot into making it secure, you can&#8217;t be too careful  whenever potentially exposing your personal data to the internet. If resources are limited, you may consider setting up a <a href="https://opnsense.org/">opnsense</a> or <a href="https://www.pfsense.org/">pfsense</a> firewall. Your security is in your own hands.</p>



<h2 class="wp-block-heading">Initial Setup</h2>



<p><strong>Note: </strong>This guide is for anyone who wants to DIY. If you would like a complete setup like this but are overwhelmed by the amount of work involved, I&#8217;d be more than happy to get you set up for a very reasonable price. More than just that, I&#8217;d guarantee my work as well. If you&#8217;re interested, send me a message via the contact form here. </p>



<p>For matters of convenience we&#8217;ll be running this setup as root &#8211; when you&#8217;re dealing with this much terminal work, <code>sudo</code> get&#8217;s old very quickly. We&#8217;ll start with setting up our storage device (in my case, a second hard drive) where we&#8217;ll be storing our Nextcloud data.</p>



<h3 class="wp-block-heading">Setting up Storage </h3>



<p>First we&#8217;ll create a mountpoint for our second storage device:</p>



<pre class="wp-block-code"><code>mkdir /mnt/storage</code></pre>



<p>Next we&#8217;ll go ahead and partition our secondary storage device. <strong>NOTE! This process will completely erase all the data on the drive.</strong>  Again, if you&#8217;re attempting what&#8217;s laid out in this article then you should know how to identify the drive you want to use with <code>fdisk</code> &#8211; in my case it is <code>/dev/sdb</code> so:</p>



<pre class="wp-block-code"><code>fdisk /dev/sdb
g # Creates new partition table
n # Creates new partition
w # Writes changes to disk</code></pre>



<p>So now that we have the disk partitioned, we can go ahead and add a filesystem to it:</p>



<pre class="wp-block-code"><code>mkfs.ext4 /dev/sdb1</code></pre>



<p>If everything went well, the disk is now ready for use. We&#8217;ll continue by creating an <code>fstab</code> entry for it and mounting it.</p>



<pre class="wp-block-code"><code>nano /etc/fstab

# Add the following
/dev/sdb1    /mnt/storage    ext4    defaults    1    2</code></pre>



<p>After saving and closing the <code>fstab</code> file, the storage can be mounted with the <code>mount -a</code> command &#8211; you can follow that with the <code>mount</code> command to see what is currently mounted (if everything went well you should see a line that corresponds to the drive we just added).</p>



<pre class="wp-block-code"><code>mount -a
mount

...
/dev/sdb1 on /mnt/storage type ext4 (rw,relatime)</code></pre>



<p>Finally let&#8217;s create a directory for our Nextcloud data on the storage we just added and set the proper permissions.</p>



<pre class="wp-block-code"><code>mkdir -p /mnt/storage/nextcloud/data
chown -R www-data:www-data /mnt/storage/nextcloud
chmod -R 755 /mnt/storage/nextcloud</code></pre>



<p>Now we&#8217;re ready to install the packages for our base Nextcloud install.</p>



<h3 class="wp-block-heading">Setting up Dependancies</h3>



<p>Back at the terminal:</p>



<pre class="wp-block-code"><code>apt-get install apache2 libapache2-mod-php mariadb-server php-xml php-cli php-cgi php-mysql php-mbstring php-gd php-curl php-zip wget unzip php-intl php-bcmath php-gmp</code></pre>



<p>Do you have to use <code>apt-get</code>? No. Why do I use it instead of <code>apt</code>? Well when I started with Debian as a young gecko, the options were <code>apt-get</code> or <code>aptitude</code> &#8211; old habits die hard. Moving on, we&#8217;ll need to edit our PHP config file to add our timezone:</p>



<pre class="wp-block-code"><code>nano /etc/php/7.3/apache2/php.ini

# Add the following line to set your timezone
date.timezone = Asia/Kolkata</code></pre>



<p>After saving and exiting the file, we&#8217;ll need to start up <code>apache</code> and <code>mariadb</code> and set them to autostart on boot.</p>



<pre class="wp-block-code"><code>systemctl start apache2
systemctl enable apache2
systemctl start mariadb
systemctl enable mariadb</code></pre>



<p>At this point we&#8217;re ready to create a database for our Nextcloud installation. Let&#8217;s start by setting a password for the &#8220;root&#8221; user in <code>mariadb</code>. </p>



<pre class="wp-block-code"><code>mysql -u root -p</code></pre>



<p>After setting the root password, we&#8217;ll create the database as well as a user for that database.</p>



<pre class="wp-block-code"><code>CREATE DATABASE nextclouddb;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY '&#91;pick a good password];
GRANT ALL ON nextclouddb.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;</code></pre>



<p>As a technical note, the <code>FLUSH PRIVILEGES</code> command is <a href="https://dev.mysql.com/doc/refman/5.7/en/privilege-changes.html">not actually necessary</a> here as we did all of our work without using <code>INSERT</code>, <code>UPDATE</code>, or <code>DELETE</code> statements. So why add it? It&#8217;s a good habit to get into &#8211; that&#8217;s all.</p>



<p>As our last step in this section, we&#8217;ll go ahead and secure our database. Honestly this is something that you should do <em>every time</em> you set up a database.</p>



<pre class="wp-block-code"><code>mysql_secure_installation</code></pre>



<h3 class="wp-block-heading">Install the Nextcloud Base</h3>



<p>Let&#8217;s start by grabbing the latest Nextcloud archive from their site. At the time of writing the latest version was 21.0.2:</p>



<pre class="wp-block-code"><code>wget https://download.nextcloud.com/server/releases/nextcloud-21.0.2.zip</code></pre>



<p>Unpack that archive to the current working directory:</p>



<pre class="wp-block-code"><code>unzip nextcloud-21.0.2.zip</code></pre>



<p>Now we&#8217;ll move the extracted files to our webserver directory and set the proper permissions:</p>



<pre class="wp-block-code"><code>mv nextcloud /var/www/
chown -R www-data:www-data /var/www/nextcloud
chmod -R 755 /var/www/nextcloud</code></pre>



<p>After that we will need to add a virtual host file for Nextcloud in apache&#8217;s configuration:</p>



<pre class="wp-block-code"><code>nano /etc/apache2/sites-available/nextcloud.conf

# Add the following lines
&lt;VirtualHost *:80&gt;
     ServerAdmin admin@example.com
     DocumentRoot /var/www/nextcloud/
     ServerName your.domain.example.com

     &lt;Directory /var/www/nextcloud/&gt;
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
          &lt;IfModule mod_dav.c&gt;
            Dav off
          &lt;/IfModule&gt;
        SetEnv HOME /var/www/nextcloud
        SetEnv HTTP_HOME /var/www/nextcloud
     &lt;/Directory&gt;

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

&lt;/VirtualHost&gt;</code></pre>



<p>After saving and closing the file we just created, we can load our new virtual host and some required modules in apache. In the example below I also disabled the default site that ships with apache.</p>



<pre class="wp-block-code"><code># Disables default site
a2dissite 000-default.conf

# Enables Nextcloud site
a2ensite nextcloud.conf

# Enables the required apache modules
a2enmod rewrite
a2enmod headers</code></pre>



<p>Finally, we&#8217;ll need to restart apache to load the changes we&#8217;ve made.</p>



<pre class="wp-block-code"><code>service apache2 restart</code></pre>



<p>At this point you should be able to access the WebGUI installer at <span class="highlight">http://your_server_ip/index.php</span></p>



<h3 class="wp-block-heading">Finishing up the Base Install</h3>



<p>On accessing the WebGUI you should see some options for finishing the basic setup. A few things of note. First the &#8220;Data Folder&#8221; should be set to the secondary storage device that we created earlier in this tutorial. Second, when configuring the database connection, remember this should be the username and password of the user we created in the database &#8211; not the account that you are running commands from. Finally, there is the option to &#8220;Install recommended apps&#8221;, and in this tutorial we want that option checked. All things said, your configuration should look something like this:</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="615" height="964" src="https://tech-jungle.com/wp-content/uploads/2021/06/Nextcloud-Setup.jpg" alt="" class="wp-image-289" srcset="https://tech-jungle.com/wp-content/uploads/2021/06/Nextcloud-Setup.jpg 615w, https://tech-jungle.com/wp-content/uploads/2021/06/Nextcloud-Setup-191x300.jpg 191w" sizes="(max-width: 615px) 100vw, 615px" /></figure>



<p>The installer should run for a bit and then send you to the dashboard.</p>



<h2 class="wp-block-heading">The Bells and Whistles</h2>



<p>At this point we have the basic setup finished, but there is still a bit to be desired. As an example, if you go to Settings &gt; Overview (or http://your_server_ip/index.php/settings/admin/overview) you&#8217;ll see something like this:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="494" src="https://tech-jungle.com/wp-content/uploads/2021/06/Nextcloud-Bells-1024x494.jpg" alt="" class="wp-image-290" srcset="https://tech-jungle.com/wp-content/uploads/2021/06/Nextcloud-Bells-1024x494.jpg 1024w, https://tech-jungle.com/wp-content/uploads/2021/06/Nextcloud-Bells-300x145.jpg 300w, https://tech-jungle.com/wp-content/uploads/2021/06/Nextcloud-Bells-768x370.jpg 768w, https://tech-jungle.com/wp-content/uploads/2021/06/Nextcloud-Bells-1536x741.jpg 1536w, https://tech-jungle.com/wp-content/uploads/2021/06/Nextcloud-Bells.jpg 1640w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Security &amp; Setup Warnings</figcaption></figure>



<p>So we&#8217;ll clear up those errors as well as tune some things that aren&#8217;t even mentioned above. Starting with caching.</p>



<h3 class="wp-block-heading">Caching for Nextcloud</h3>



<p>As <a href="https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/caching_configuration.html">per the official documentation</a>, there are a few options when it comes to caching but essentially it boils down to this: </p>



<p>For the best performance you will need two different caching systems. </p>



<p>One of them will cache the PHP code used by Nextcloud, and the other will cache file/database actions.   </p>



<p>That said, we&#8217;ll start by setting up <a href="https://pecl.php.net/package/APCu">APCu</a>, which is our PHP cache of choice.</p>



<pre class="wp-block-code"><code>apt-get install php-apcu php-apcu-bc</code></pre>



<p>Next you&#8217;ll need to edit your <code>php.ini</code> file. We will make some changes to the configuration to avoid issues with the caching system and to tune PHP a bit. This will actually also resolve the &#8220;PHP Memory&#8221; prompt also).</p>



<pre class="wp-block-code"><code>nano /etc/php/7.3/apache2/php.ini

; Add the following wherever you would like

;;;;;;;;;;;;;;;;;;;;
;     Nextcloud    ;
;;;;;;;;;;;;;;;;;;;;
apc.enable_cli = 1

; Then scroll through the file and modify the following parameters
max_execution_time = 300
memory_limit = 512M
post_max_size = 500M
upload_max_filesize = 500M</code></pre>



<p>After saving and closing your PHP ini file, we&#8217;ll need to tell our Nextcloud instance to use the cache. While we are here, we&#8217;ll also add our local date time to the config file as this will resolve the &#8220;Your installation has no default phone region set.&#8221; prompt.</p>



<pre class="wp-block-code"><code>nano /var/www/nextcloud/config/config.php

# Add to the configuration array for caching
'memcache.local' =&gt; 'OC\Memcache\APCu',

# Add to the configuration array to set the local date time
'default_phone_region' =&gt; 'IN',</code></pre>



<p>After saving and closing that file, you can restart apache and see how the new cache is working. Alternatively, you can just continue on to the next part where we setup our file/database cache.</p>



<p>For our file/database cache we&#8217;ll be using <a href="https://redis.io/">redis</a>. In addition to caching, redis also offers transactional file locking &#8211; which essentially protects against file corruption. Right out the gate:</p>



<pre class="wp-block-code"><code>apt-get install redis-server php-redis</code></pre>



<p>After installing those packages and their dependencies we will configure the redis server:</p>



<pre class="wp-block-code"><code>nano /etc/redis/redis.conf

# Modify the following parameters
port 0
unixsocket /var/run/redis/redis-server.sock
unixsocketperm 0770</code></pre>



<p>After saving and closing the file, we&#8217;ll need to add the webserver user to the redis server group:</p>



<pre class="wp-block-code"><code>usermod -a -G redis www-data</code></pre>



<p>Back to our nextcloud configuration file, we&#8217;ll need to instruct our Nextcloud instance to use the redis service:</p>



<pre class="wp-block-code"><code>nano /var/www/nextcloud/config/config.php

# Add to the configuration array for caching
  'memcache.distributed' =&gt; '\OC\Memcache\Redis',
  'redis' =&gt; &#91;
      'host'     =&gt; '/var/run/redis/redis-server.sock',
      'port'     =&gt; 0,
  ],</code></pre>



<p>Finally, we&#8217;ll start and enable the redis service to run at boot, and then restart apache:</p>



<pre class="wp-block-code"><code>systemctl start redis-server
systemctl enable redis-server
service apache2 restart</code></pre>



<p>At this point, the caching should be set up and running correctly.</p>



<h3 class="wp-block-heading">Set up HTTPS</h3>



<p>Running anything over the internet in plaintext is a no-no, especially when a proper TLS setup can be done for free. For this we&#8217;ll be using <a href="https://certbot.eff.org/">certbot</a>, but first, a few things to note.</p>



<p>The method I&#8217;m going demonstrate here <em>requires </em>that you have port-forwarding to your server configured correctly for ports 80 and 443 (non-standard ports can&#8217;t be used with this method). If you aren&#8217;t using a commercial leased line, your ISP most likely filters those ports, so it may come down to calling their support line and asking for them to unblock them. In any case, you must make sure that traffic over those ports can reach your server. It goes without saying that you&#8217;ll also need a domain name for your Nextcloud instance. If you proceed with the setup below without ensuring traffic can reach your server correctly, after 5 times of erroring out certbot will <a href="https://community.letsencrypt.org/t/too-many-failed-authorizations-recently/91444">block any following requests for 1 hour</a>. Now that&#8217;s out of the way, let&#8217;s proceed.</p>



<pre class="wp-block-code"><code>apt-get install python-certbot-apache</code></pre>



<p>Now that certbot is installed, you can run the following to request a TLS certificate for your site. At the end of this operation you will have the choice to redirect all HTTP traffic to HTTPS &#8211; this is recommended. </p>



<pre class="wp-block-code"><code>certbot --apache -d your.domain.example.com</code></pre>



<p>At this point you should be able to access your Nextcloud instance by it&#8217;s domain name (e.g your.domain.example.com). If you do, you will be greeted with this message:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="964" height="473" src="https://tech-jungle.com/wp-content/uploads/2021/06/Untrusted-Domain.jpg" alt="" class="wp-image-292" srcset="https://tech-jungle.com/wp-content/uploads/2021/06/Untrusted-Domain.jpg 964w, https://tech-jungle.com/wp-content/uploads/2021/06/Untrusted-Domain-300x147.jpg 300w, https://tech-jungle.com/wp-content/uploads/2021/06/Untrusted-Domain-768x377.jpg 768w" sizes="(max-width: 964px) 100vw, 964px" /><figcaption>Untrusted Domain Blocked</figcaption></figure>



<p>This is normal, as Nextcloud only allows access through domains set in the <code>config.php</code> file. To allow access from your domain name is as simple as:</p>



<pre class="wp-block-code"><code>nano /var/www/nextcloud/config/config.php

# Add your domain in the "trusted_domains" array eg.
'trusted_domains' =&gt;
 array (
    0 =&gt; '192.168.1.10', # This is the pre-existing domain for the local network

    1 =&gt; 'your.domain.example.com', # This is the line you should add to allow your domain
 ),</code></pre>



<p>After saving and exiting that file, restart apache and you should be able to access your Nextcloud instance by it&#8217;s domain name.</p>



<p>To wrap this up, we&#8217;ll add a cron entry that will auto-renew our TLS certificate when possible. By default, certbot only offers certificates that are valid for 90 days. Instead of manually logging in to renew the certificate every three months it&#8217;s much simpler to simply automate the renewal:</p>



<pre class="wp-block-code"><code>crontab -e

# Add the following
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
0 */12 * * * root certbot -q renew --apache</code></pre>



<p>After saving and closing the crontab, the system will automatically renew your TLS certificate on the 12th of every month when possible.</p>



<h3 class="wp-block-heading">Tightening Security </h3>



<p>Now that we have HTTPS set up, it&#8217;s a good idea to leverage some of the security options available. One such options is enabling <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security">Strict Transport Security</a>. I won&#8217;t go into detail on what that is here, but setting it up is fairly simple.</p>



<pre class="wp-block-code"><code>nano /etc/apache2/sites-available/nextcloud-le-ssl.conf

# Add the following to the very top (before everything else)
&lt;IfModule mod_headers.c&gt;
      Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
&lt;/IfModule&gt;</code></pre>



<p>Restart apache and Strict Transport Security should be enabled.</p>



<h3 class="wp-block-heading">Scheduling Tasks with Cron</h3>



<p>By default, Nextcloud uses AJAX to run background jobs &#8211; it will run one taks with each page loaded. While this works, scheduling with cron is better. So at the command line:</p>



<pre class="wp-block-code"><code>crontab -u www-data -e

# Add the following
*/5  *  *  *  * php -f /var/www/nextcloud/cron.php</code></pre>



<p>After saving and exiting the crontab, you can validate your changes like so:</p>



<pre class="wp-block-code"><code>crontab -u www-data -l</code></pre>



<p>To finish enabling cron scheduling, login to your Nextcloud instance and go to User &gt; Settings &gt; Basic settings. There select the &#8220;Cron&#8221; option.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="492" src="https://tech-jungle.com/wp-content/uploads/2021/06/Cron-Setup-1024x492.jpg" alt="" class="wp-image-294" srcset="https://tech-jungle.com/wp-content/uploads/2021/06/Cron-Setup-1024x492.jpg 1024w, https://tech-jungle.com/wp-content/uploads/2021/06/Cron-Setup-300x144.jpg 300w, https://tech-jungle.com/wp-content/uploads/2021/06/Cron-Setup-768x369.jpg 768w, https://tech-jungle.com/wp-content/uploads/2021/06/Cron-Setup-1536x737.jpg 1536w, https://tech-jungle.com/wp-content/uploads/2021/06/Cron-Setup.jpg 1910w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption>Enabling Cron Scheduling</figcaption></figure>



<h3 class="wp-block-heading">Thumbnails Pls</h3>



<p>By default, Nextcloud won&#8217;t generate thumbnails &#8211; I mean &#8220;previews&#8221; (don&#8217;t ask me why the redefinition) for many file types &#8211; PDFs and movie files being a few. <a href="https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/previews_configuration.html">The developer&#8217;s reason</a> for this is &#8220;Due to security concerns&#8221;. After a bit of digging, it turns out the reason for this is based on the fact that previews are generated by <a href="https://github.com/nextcloud/documentation/issues/710">PHP libraries written in C</a>, and as such could be vulnerable to attack vectors.</p>



<p>However that isn&#8217;t the only consideration &#8211; generating previews for movies (for example) can use quite a bit of CPU time. That said, it&#8217;s up to you whether or not this is for you. If it is, here&#8217;s how to go about setting it up:</p>



<pre class="wp-block-code"><code>apt-get install imagemagick-common ffmpeg</code></pre>



<p>Next we&#8217;ll need to edit our config.php file to add the &#8220;preview&#8221; functionality:</p>



<pre class="wp-block-code"><code># Add the following array
'enabledPreviewProviders' =&gt;
 array (
    'OC\Preview\Movie',
    'OC\Preview\PNG',
    'OC\Preview\JPEG',
    'OC\Preview\GIF',
    'OC\Preview\MP3',
    'OC\Preview\MP4',
    'OC\Preview\TXT',
    'OC\Preview\PDF',
 ),</code></pre>



<p>After (you should have seen this coming) restarting apache, previews for the file types listed above should start being generated. If that doesn&#8217;t happen, you may need to kick off the preview generation manually:</p>



<pre class="wp-block-code"><code>su - www-data -s /bin/bash -c "/var/www/nextcloud/occ maintenance:mimetype:update-js"
su - www-data -s /bin/bash -c "/var/www/nextcloud/occ maintenance:mimetype:update-db"</code></pre>



<h3 class="wp-block-heading">Problematic PDF Viewer</h3>



<p>At this point, you setup is probably feeling pretty sweet. That is until you go to open a PDF file and get this error:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="518" src="https://tech-jungle.com/wp-content/uploads/2021/06/PDF-Viewer-Issue-1024x518.jpg" alt="" class="wp-image-295" srcset="https://tech-jungle.com/wp-content/uploads/2021/06/PDF-Viewer-Issue-1024x518.jpg 1024w, https://tech-jungle.com/wp-content/uploads/2021/06/PDF-Viewer-Issue-300x152.jpg 300w, https://tech-jungle.com/wp-content/uploads/2021/06/PDF-Viewer-Issue-768x389.jpg 768w, https://tech-jungle.com/wp-content/uploads/2021/06/PDF-Viewer-Issue-1536x778.jpg 1536w, https://tech-jungle.com/wp-content/uploads/2021/06/PDF-Viewer-Issue.jpg 1920w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption>PDF Viewer Fail</figcaption></figure>



<p>If you don&#8217;t have this issue, great! That means the Nextcloud team patched it. However if you did encounter it, the fix is pretty simple, let&#8217;s JavaScript:</p>



<pre class="wp-block-code"><code>nano /var/www/nextcloud/apps/files_pdfviewer/js/files_pdfviewer-main.js

# Find the string
!==i&#91;a]&amp;&amp;(c+="/"+encodeURIComponent(i&#91;a]));return t&amp;&amp;(c=i&#91;0]+"//"+i&#91;2]+c),c}}

# Replace that string with
!==i&#91;a]&amp;&amp;(c+="/"+i&#91;a]);return t&amp;&amp;(c=i&#91;0]+"//"+i&#91;2]+c),c}}</code></pre>



<p>Restart apache and clear your browser&#8217;s cache and the PDF file viewer should now function properly.</p>



<h3 class="wp-block-heading">Set up DNS Redirection</h3>



<p>If you&#8217;re set Nextcloud up as an on-premise/off-premise service (e.g. you have a server running next cloud at an office) then it makes sense to avoid routing on-premise traffic to the Nextcloud instance over the WAN. Essentially, routing local traffic directly to the server saves WAN usage, is more robust (clients will still have access even if the internet goes out), and will be faster (local network speeds instead of WAN speeds). This is pretty simple to set up assuming you are running your own local DNS server. Simply add an <a href="https://support.dnsimple.com/articles/a-record/">A Record</a> to your DNS server with the URL of your server and it&#8217;s local IP. For example:</p>



<pre class="wp-block-code"><code>A your.domain.example.com 192.168.1.10</code></pre>



<p>At this point your local clients should now seamlessly connect to the local instance &#8211; notice the difference in latency. <img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<h2 class="wp-block-heading">Final Notes</h2>



<p>After having spent days digging through articles and forums to piece this together, I can honestly say I&#8217;m glad to be done with this. That said, hopefully me writing it out here has saved you some time if you&#8217;ve decided to undertake this also.</p>



<p>If there&#8217;s something regarding a Nextcloud setup that you would like to see here but don&#8217;t, just leave me a message in the comments and I&#8217;ll add a walkthrough for it to this &#8220;Bells and Whistles&#8221; section. If you&#8217;d like to see some of the other writeups I&#8217;ve done, you can find them on my <a href="https://tech-jungle.com/blog/">blog</a> page.</p>



<p><strong>Mandatory Plug:</strong> If you like seeing content like this maybe consider throwing some <a href="https://brave.com/brave-rewards/">BAT</a> at your boy. If you&#8217;d like to contribute but want to do it through a different avenue just let me know. Thank you for reading. <img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a href="https://tech-jungle.com/properly-setting-up-nextcloud-21-on-debian-10-buster/">Properly Setting up Nextcloud 21 on Debian 10 (Buster)</a> appeared first on <a href="https://tech-jungle.com">Tech Jungle</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tech-jungle.com/properly-setting-up-nextcloud-21-on-debian-10-buster/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
