How to Fix “E: unable to locate package” Error in Debian 9

‘,
enableHover: false,
enableTracking: true,
buttons: { twitter: {via: ‘tecmint’}},
click: function(api, options){
api.simulateClick();
api.openPopup(‘twitter’);
}
});
jQuery(‘#facebook’).sharrre({
share: {
facebook: true
},
template: ‘{total}’,
enableHover: false,
enableTracking: true,
click: function(api, options){
api.simulateClick();
api.openPopup(‘facebook’);
}
});
jQuery(‘#googleplus’).sharrre({
share: {
googlePlus: true
},
template: ‘{total}’,
enableHover: false,
enableTracking: true,
urlCurl: ‘https://www.tecmint.com/wp-content/themes/tecmint/js/sharrre.php’,
click: function(api, options){
api.simulateClick();
api.openPopup(‘googlePlus’);
}
});
jQuery(‘#linkedin’).sharrre({
share: {
linkedin: true
},
template: ‘{total}’,
enableHover: false,
enableTracking: true,
buttons: {
linkedin: {
description: ‘How to Fix “E: unable to locate package” Error in Debian 9’,media: ‘https://www.tecmint.com/wp-content/uploads/2017/08/Fix-Unable-to-Locate-Package-on-Debian-9.png’ }
},
click: function(api, options){
api.simulateClick();
api.openPopup(‘linkedin’);
}
});
// Scrollable sharrre bar, contributed by Erik Frye. Awesome!
var shareContainer = jQuery(“.sharrre-container”),
header = jQuery(‘#header’),
postEntry = jQuery(‘.entry’),
$window = jQuery(window),
distanceFromTop = 20,
startSharePosition = shareContainer.offset(),
contentBottom = postEntry.offset().top + postEntry.outerHeight(),
topOfTemplate = header.offset().top;
getTopSpacing();
shareScroll = function(){
if($window.width() > 719){ var scrollTop = $window.scrollTop() + topOfTemplate,
stopLocation = contentBottom – (shareContainer.outerHeight() + topSpacing);
if(scrollTop > stopLocation){
shareContainer.offset({top: contentBottom – shareContainer.outerHeight(),left: startSharePosition.left});
}
else if(scrollTop >= postEntry.offset().top-topSpacing){
shareContainer.offset({top: scrollTop + topSpacing, left: startSharePosition.left});
}else if(scrollTop 1024)
topSpacing = distanceFromTop + jQuery(‘.nav-wrap’).outerHeight();
else
topSpacing = distanceFromTop;
}
});
]]>

How to Install Apache, MariaDB and PHP (FAMP) Stack on FreeBSD

This guide will describe how to install and configure FBAMP in FreeBSD operating system, which is similar to a LAMP stack on Linux. FBAMP is an acronym which stands for a collection of software based on FreeBSD OS, Apache HTTP server, the most popular open-source web server in internet, MariaDB relational database management system (RDBMS), a fork of MySQL database engine, and PHP server-side.

Requirements

  1. A fresh installation of FreeBSD
  2. FreeBSD Initial Configurations
  3. Direct console access or SSH in case of a remote connection to FreeBSD.
  4. A static IP Address configured on a Network Interface.

Step 1: Install Apache on FreeBSD

1. The first service we’ll install is Apache HTTP server. By default, FreeBSD offers multiple versions with different runtime work modules for Apache web server.

The versions are pre-compiled into a binary package and provided by FreeBSD PORTS repositories. To display all Apache packages binaries provided by PORTS, issue the following command.

# ls /usr/ports/www/ | grep apache
List Apache Packages on FreeBSD

List Apache Packages on FreeBSD

You can also search for available pre-complied Apache packages on FreeBSD by issuing the below command.

# pkg search apache2
Search Apache Packages on FreeBSD

Search Apache Packages on FreeBSD


2. Next, install the latest version of Apache HTTP server with all required modules by issuing the following command.

# pkg install apache24
Install Apache on FreeBSD

Install Apache on FreeBSD

3. After Apache web server has been installed on the system, issue the following command to enable the daemon system-wide in FreeBSD.

# sysrc apache24_enable="yes"

An alternative method of enabling Apache daemon would be to manually edit and append the line apache24_enable="yes" in /etc/rc.conf file as illustrated in the below screenshot.

Enable Apache System Wide on FreeBSD

Enable Apache System Wide on FreeBSD

4. Finally, to test if the web server is properly working, start Apache daemon by issuing the below command and visit the default web page by pointing a browser to your server IP address of FQDN (http://IP-orFQDN) as shown in the below screenshot.

# service apache24 start
Start Apache Service

Start Apache Service

Verify Apache Page

Verify Apache Page

The default webroot directory of Apache web server in FreeBSD 11.x is located in /usr/local/www/apache24/data/ system path. There you will find a small index.html file you can edit as preferably.

Apache DocumentRoot on FreeBSD

Apache DocumentRoot on FreeBSD

Step 2: Install PHP on FreeBSD

5. FreeBSD 11.x offers multiple versions of PHP interpreted server-side language packaged in pre-complied binaries. To get a list of all available PHP version packages provided by FreeBSD Ports repositories issue the following command.

# ls /usr/ports/lang/ | grep php
List PHP Versions in FreeBSD

List PHP Versions in FreeBSD

An alternative method of searching for all available FreeBSD PHP package versions is by running the below command.

# pkg search -o php
Search PHP Versions in FreeBSD

Search PHP Versions in FreeBSD

6. To search for all available binaries provided by FreeBSD for a specific PHP version (5 or 7 versions currently) run the below commands. Use less command to narrow and navigate through the output.

# pkg search php5 |less
# pkg search php7
List PHP 5 Packages on FreeBSD

List PHP 5 Packages on FreeBSD

List PHP 7 Packages on FreeBSD

List PHP 7 Packages on FreeBSD

7. To be more specific on what modules a custom PHP version provides, run the following command as described below, which display all available modules for PHP 7.1 version.

# pkg search php71
List PHP Modules on FreeBSD

List PHP Modules on FreeBSD

8. In this guide we’ll install PHP 7.1 release for our FBAMP stack. Issue the following command to install PHP with some of the most important modules required for a typical CMS installation.

# pkg install php71 mod_php71 php71-mbstring php71-mcrypt php71-zlib php71-curl php71-gd php71-json 

9. Next, we need to create the php.conf configuration file for Apache web server in /usr/local/etc/apache24/Includes/ system path with the following content.

# nano /usr/local/etc/apache24/Includes/php.conf

Add the following lines to php.conf file.

<IfModule dir_module>
DirectoryIndex index.php index.html
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
</IfModule>
Configure PHP for Apache on FreeBSD

Configure PHP for Apache on FreeBSD

10. In order to test if PHP gateway is working as expected with Apache web server, create a PHP info.php file in /usr/local/www/apache24/data/system path, which is the default web document root path of Apache web server.

# echo '<?php phpinfo(); ?>' | tee -a /usr/local/www/apache24/data/info.php

Restart Apache daemon to apply changes.

# service apache24 restart

Next, visit the following URI in a browser to view PHP summary.

http://IP-or-FQDN/info.php 
Verify PHP Modules on FreeBSD

Verify PHP Modules on FreeBSD

11. In order to activate PHP ini configuration file for production issue the below commands. You can modify php.ini production file in order to change diverse PHP settings in your FBAMP stack.

# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini-production.bakup
# ln -s /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Step 3: Install MariaDB on FreeBSD

12. The last missing component for our FBAMP stack is MySQL database server. FreeBSD 11.x offer more than 1000 packages for diverse databases.

In order to display what components are available for MariaDB or MySQL databases, issue the following commands. In this guide we’ll install MariaDB database over MySQL (which is now owned and developed actively by Oracle).

# ls -al /usr/ports/databases/ | grep mariadb
# pkg search -o mariadb
# ls -al /usr/ports/databases/ | grep mysql
# pkg search -o mysql5
List MariaDB Versions on FreeBSD

List MariaDB Versions on FreeBSD

Search MariaDB Versions on FreeBSD

Search MariaDB Versions on FreeBSD

13. In this guide we’ll install the latest version of MariaDB database server in FreeBSD, which currently is represented by mariadb102 binary package release.

Run the following command in order to install MariaDB server and client and the required PHP 7.1 module needed to access the database via Apache server gateway.

# pkg install mariadb102-server mariadb102-client php71-mysqli

14. Next, enable MariaDB server system-wide and start the database daemon by running the following commands.

# sysrc mysql_enable="yes" # service mysql-server start

15. To secure the database run mysql_secure_installation scrip. Use the below script output excerpt to harden MariaDB.

# /usr/local/bin/mysql_secure_installation
Sample Output

MySQL Secure Installation Script Output

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

16. By default, MariaDB daemon listens for network connections outside localhost on port 3306/TCP. Run netstat, lsof or sockstat command to get MariaDB socket state. This configuration is dangerous and exposes the service to outside network attacks.

# lsof -i4 -i6
# sockstat -4 -6
Verify MariaDB Port

Verify MariaDB Port

17. If you don’t need remote access to MariaDB, make sure MariaDB daemon listens to localhost only, by issuing the below command. Subsequently, restart MariaDB service to apply changes.

# sysrc mysql_args="--bind-address=127.0.0.1"
# service mysql-server restart
or
# /usr/local/etc/rc.d/mysql-server restart

18. Again, run netstat, lsof or sockstat command in order to list MariaDB network socket. The socket should bind and listen on localhost now, as illustrated in the below image.

# lsof -i4 | grep mysql
# netstat -an | grep 3306
# sockstat -4 | grep 3306
Check MariaDB Listening on Localhost

Check MariaDB Listening on Localhost

19. To test MariaDB database connectivity from console issue the following command. Enter MySQL root password in prompt and a list of default databases should be displayed in your console screen as illustrated in the below image.

# mysql -u root -p -e "show databases"
List MySQL Databases

List MySQL Databases

That’s all! You’ve successfully installed Apache web server with MariaDB database and PHP interpreter in FreeBSD. You can now start to deploy a WordPress website in no time.

On the next tutorial we’ll discuss some advanced FPBAMP topics, such as how to enable and create Apache virtual hosts, enable rewrite module required by .htaccess file to function properly and how to secure Apache connections using a Self-Signed certificate or a free Certificate offered by Let’s Encrypt entity.

How to Install PostgreSQL 9.6 on Debian and Ubuntu

PostgreSQL is a powerful, highly scalable, open source and cross-platform object-relational database system that runs on Unix-like operating systems including Linux and Windows OS. It is an enterprise level database system which is highly reliable and offers data integrity and correctness to users.

In our earlier article, we’ve explained PostgreSQL 10 installation on CentOS/RHEL and Fedora. In this article, we will explain how to install PostgreSQL 9.6 on Debian, Ubuntu and its derivatives using official PostgreSQL APT repository.

Add PostgreSQL APT Repository

This official PostgreSQL APT repository will combine with your Linux system and offers automatic updates for all supported versions of PostgreSQL on Debian and Ubuntu distributions.

To add the apt repository, first create the file /etc/apt/sources.list.d/pgdg.list, and add a line for the repository as per your distribution.

On Ubuntu Systems

--------------- On Ubuntu 17.04 ---------------
deb http://apt.postgresql.org/pub/repos/apt/ zesty-pgdg main
--------------- On Ubuntu 16.04 ---------------
deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main
--------------- On Ubuntu 14.04 ---------------
deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main

On Debian Systems

--------------- On Stretch 9.x ---------------
deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main
--------------- On Jessie 8.x ---------------
deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main
--------------- On Wheezy 7.x ---------------
deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main


Then import the repository signing key, and update the system package lists like this.

$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt update 
Add PostgreSQL Key

Add PostgreSQL Key

Install PostgreSQL Server

Once you have added the PostgreSQL apt repository in your respective Linux distribution, now install PostgreSQL server and client packages as follows:

$ sudo apt install postgresql-9.6-server postgresql-9.6 
Install Postgresql Database Server

Install Postgresql Database Server

Important: Unlike in RHEL/CentOS/Fedora where you have to manually initialize the database system, in Ubuntu/Debian, it is initialized automatically. Therefore simply proceed to start database server as described in the next section.

The PostgreSQL data directory /var/lib/postgresql/9.6/main contains all of the data files for the database.

Start and Enable PostgreSQL Server

With the database server initialized, start PostgreSQL service and enable PostgreSQL service to auto start on system boot like this.

--------------- On SystemD --------------- $ sudo systemctl start postgresql.service
$ sudo systemctl enable postgresql.service $ sudo systemctl status postgresql.service --------------- On SysVinit --------------- $ sudo service postgresql-9.6 start
$ sudo chkconfig postgresql on
$ sudo service postgresql-9.6 status
Start and Enable PostgreSQL Database

Start and Enable PostgreSQL Database

Verify PostgreSQL Installation

After installing PostgreSQL database system on your server, verify its installation by connecting to postgres database server. The PostgreSQL administrator user is named as postgres, type this command to access the user system account.

$ sudo su postgres
# cd
# psql
Verify PostgreSQL Database

Verify PostgreSQL Database

To set a password for the postgre database administrator user, use this command:

postgres=# \password postgres
Set Password for PostgreSQL Admin

Set Password for PostgreSQL Admin

To secure the postgre user system account, use the password command below.

$ sudo passwd postgres Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
$su - postgre
$ ls
$ psql
Set Password for Postgre User

Set Password for Postgre User

For more information, go to the PostgreSQL Homepage: https://www.postgresql.org/

Lastly, also read through these articles about popular database management systems:

  1. Installing MariaDB 10.1 in Debian Jessie and Running Various MariaDB Queries
  2. How to Change a Default MySQL/MariaDB Data Directory in Linux
  3. How to Install and Secure MariaDB 10 in CentOS 7
  4. How to Install and Secure MariaDB 10 in CentOS 6
  5. Install MongoDB Community Edition 3.2 on Linux Systems

That’s all for now! To share any thoughts with us, make use of the feedback form below. Remember to always stay connected to Tecmint.com for interesting Linux stuff.

How to Boost Linux Server Internet Speed with TCP BBR

BBR (Bottleneck Bandwidth and RTT) is a relatively new congestion control algorithm written by software engineers at Google. It is the latest solution out of Google’s persistent attempts to make the Internet faster via the TCP protocol – the workhorse of the Internet.

The primary aim of BBR is to boot network utilization and reduce queues (that result into slow network activity): it should be deployed on servers, but not in the network or the client side. In Linux, BBR is implemented in kernel version 4.9 or higher.

In this article, we will briefly explain TCP BBR, then proceed to show how to boost a Linux server Internet speed using TCP BBR congestion control in Linux.

Requirements

You should have Linux kernel version 4.9 or above installed, compiled with these options (either as a module or inbuilt into it):

  • CONFIG_TCP_CONG_BBR
  • CONFIG_NET_SCH_FQ
  • CONFIG_NET_SCH_FQ_CODEL

How to Check Kernel Modules in Linux


To check if the above options are compiled in your kernel, run these commands:

# cat /boot/config-$(uname -r) | grep 'CONFIG_TCP_CONG_BBR'
# cat /boot/config-$(uname -r) | grep 'CONFIG_NET_SCH_FQ'
Check Kernel Modules

Check Kernel Modules

To update your kernel, check out these guides:

  1. How to Upgrade Kernel to Latest Version in Ubuntu
  2. How to Install or Upgrade to Latest Kernel Version in CentOS 7

Enabling TCP BBR Congestion Control in Linux

BBR works effectively with pacing, so it must be employed together with the fq qdisc classless packet scheduler for traffic pacing. To find more information about fq qdisc, type:

# man tc-fq

With the fair understanding of BBR, you can now configure it on your server. Open the /etc/sysctl.conf file using you favorite editor.

# vi /etc/sysctl.conf

Add the options below at the end of the file.

net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
Enabling TCP BBR in Linux

Enabling TCP BBR in Linux

Save and close the file. Then effect the changes in the system using the sysctl command.

# sysctl --system

From the screen shot blow, you can see the options have been added with the appropriate values.

Verify Kernel Parameters

Verify Kernel Parameters

Testing TCP BBR Congestion Control Configuration

After performing the necessary configurations, you can test if it is practically working. There are several tools for measure bandwidth speed such as Speedtest-CLI:

  1. How to Test Your Internet Speed Bidirectionally from Command Line Using ‘Speedtest-CLI’ Tool

Other tools include bmon (bandwith monitor), nload, Wget – command based file downloader and cURL which all show network bandwidth; you can use them for testing.

BBR Github repository: https://github.com/google/bbr

You may also like to read following related articles.

  1. Setup Your Own “Speedtest Mini Server” to Test Internet Bandwidth Speed
  2. How to Limit the Network Bandwidth Used by Applications in a Linux System with Trickle
  3. How to Change Kernel Runtime Parameters in a Persistent and Non-Persistent Way

In this article, we showed how to boost Linux server Internet speed using TCP BBR congestion control in Linux. Test it comprehensively under different scenarios and give us any important feedback via the comment form below.

Credit: Nixcraft

10 Things to Do After Fresh Installation of FreeBSD

This tutorial will cover some initial configurations you need to perform on a fresh installed FreeBSD operating system and some basics on how to manage FreeBSD from command line.

Requirements

  1. FreeBSD 11.1 Installation Guide

1. Update FreeBSD System

The first thing every system administrator should perform after a fresh installation of an operating system is to make sure the system is up-to-date with the latest security patches and the latest versions of the kernel, package manager and software packages.

In order to update FreeBSD, open a console in the system with root privileges and issue the following commands.

# freebsd-update fetch
# freebsd-update install
Update FreeBSD System

Update FreeBSD System

To update “Ports” package manager and installed software run the below command.

# pkg update
# pkg upgrade
Update FreeBSD Packages

Update FreeBSD Packages

Upgrade FreeBSD Packages

Upgrade FreeBSD Packages

2. Install Editors and Bash


In order to ease the job managing the system from command line you should install the following packages:

  • Nano text editoree is the default text editor in FreeBSD.
  • Bourne Again Shell – if you want to make the transition from Linux to FreeBSD more smooth.
  • Bash Completion – needed to autocomplete commands typed in console using the [tab] key.

All the presented utilities can be installed by issuing the below command.

# pkg install nano bash bash_completion
Install Editors and Bash on FreeBSD

Install Editors and Bash on FreeBSD

3. Secure SSH on FreeBSD

By default, FreeBSD SSH service won’t allow the root account to perform remote logins automatically. Although, disallowing remote root logins via SSH measure is mainly designed to secure the service and your system, there are cases where sometimes you need to authenticate via SSH with root.

To change this behavior, open SSH main configuration file and update the line PermitRootLogin from no to yes as illustrated in the below screenshot.

# nano /etc/ssh/sshd_config 

File excerpt:

PermitRootLogin yes
Secure SSH on FreeBSD

Secure SSH on FreeBSD

Afterwards, restart SSH daemon to apply changes.

# service sshd restart

To test the configuration you can login from Putty Terminal or from remote Linux maching using the following syntax.

# [email protected] [FreeBSD Server IP]

4. FreeBSD SSH Passwordless Login

To generate a new SSH key issue the following command. You can copy the public to another server instance and securely login to the remote server without a password.

# ssh-keygen –t RSA
# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
# ssh [email protected]
Generate SSH Key on FreeBSD

Generate SSH Key on FreeBSD

FreeBSD SSH Passwordless Login

FreeBSD SSH Passwordless Login

5. Install and Configure Sudo on FreeBSD

Sudo is a software which is designed to allow a common user to execute commands with the security privileges of the superuser account. Sudo utility is not installed by default in FreeBSD.

To install sudo in FreeBSD run the following command.

# pkg install sudo
Install Sudo on FreeBSD

Install Sudo on FreeBSD

In order to allow a regular system account to run command with root privileges, open sudoers configuration file, located in /usr/local/etc/ directory, for editing by executing visudo command.

Navigate through the content of the file and add the following line, normally after the root line:

your_user ALL=(ALL) ALL
Enable Sudo Access on User

Enable Sudo Access on User

Always use visudo command in order to edit sudoers file. Visudo utility contains build-in capabilities to detect any error while editing this file.

Afterwards, save the file by pressing :wq! on your keyboard, login with the user who you’ve granted root privileges and execute an arbitrary command by appending sudo in front the command.

# su - yoursuer
$ sudo pkg update
Sudo User Login

Sudo User Login

Another method that can be used in order to allow a regular account with root powers, would be to add the regular user to system group called wheel and uncomment the wheel group from sudoers file by removing the # sign at the beginning of the line.

# pw groupmod wheel -M your_user
# visudo

Add the following line to /usr/local/etc/sudoers file.

%wheel ALL=(ALL=ALL) ALL
Allow Sudo Access on User

Allow Sudo Access on User

6. Managing Users on FreeBSD

The process of adding a new user is pretty straightforward. Just run adduser command and follow the interactive prompt in order to finalize the process.

In order to modify the personal information of a user account, run the chpass command against a username and update the file. Save the file opened with vi editor by pressing :wq! keys.

# chpass your_user
Change User Info on FreeBSD

Change User Info on FreeBSD

To update a user password, run passwd command.

# passwd your_user

To change an account default shell, first list all present shells in your system and then execute chsh command as illustrated below.

# cat /etc/shells
# chsh -s /bin/csh your_user
# env #List user environment variables
List FreeBSD Shells

List FreeBSD Shells

Change FreeBSD Shell

Change FreeBSD Shell

7. Configure FreeBSD Static IP

Regular FreeBSD permanent network settings can be manipulated by editing /etc/rc.conf file. In order to configure a network interface with static IP address on FreeBSD.

First run ifconfig -a command to display a list of all NICs and identify the name of the interface you want to edit.

Then, manually edit /etc/rc.conf file, comment the DHCP line and add your NIC’s IP settings as illustrated below.

#ifconfig_em0="DHCP"
ifconfig_em0="inet 192.168.1.100 netmask 255.255.255.0"
#Default Gateway
defaultrouter="192.168.1.1"
Set FreeBSD Static IP Address

Set FreeBSD Static IP Address

To apply the new network settings issue the following commands.

# service netif restart
# service routing restart

8. Configure FreeBSD DNS Network

DNS nameserver resolvers can be manipulated via editing /etc/resolv.conf file as presented in the below example.

nameserver your_first_DNS_server_IP
nameserver your_second_DNS_server_IP
search your_local_domain
Set DNS in FreeBSD

Set DNS in FreeBSD

To change your machine name update the hostname variable from /etc/rc.conf file.

hostname=”freebsdhost”

To add multiple IP address for a network interface on FreeBSD add the below line in /etc/rc.conf file.

ifconfig_em0_alias0="192.168.1.5 netmask 255.255.255.255"
Multiple IP Addresses on FreeBSD

Multiple IP Addresses on FreeBSD

Afterwards, restart the network service to reflect changes.

# service netif restart

9. Manage FreeBSD Services

Services can be managed in FreeBSD via service command. To list all system-wide enabled services issue the following command.

# service -e
List FreeBSD Services

List FreeBSD Services

To list all services scripts located in /etc/rc.d/ system path run the below command.

# service -l
List FreeBSD Service Scripts

List FreeBSD Service Scripts

To enable or disable a FreeBSD daemon during boot initialization process, use sysrc command. Assuming that you want to enable SSH service, open /etc/rc.conf file and append the following line.

sshd_enable=”YES”

Or use sysrc command which does the same thing.

# sysrc sshd_enable=”YES”
Enable and Disable Service on FreeBSD

Enable and Disable Service on FreeBSD

To disable a service system-wide, append the NO flag for the disabled daemon as presented below. The daemons flags are case insensitive.

# sysrc apache24_enable=no
Disable Service in FreeBSD

Disable Service in FreeBSD

Is worth mentioning that some services on FreeBSD require special attention. For example, if you want to only disable Syslog daemon network socket, issue the following command.

# sysrc syslogd_flags="-ss"

Restart Syslog service to apply changes.

# service syslogd restart
Disable Syslog on FreeBSD

Disable Syslog on FreeBSD

To completely disable Sendmail service at system startup, execute the following commands or add them to /etc/rc.conf file:

sysrc sendmail_enable="NO"
sysrc sendmail_submint_enable="NO"
sysrc sendmail_outbound_enable="NO"
sysrc sendmail_msp_queue_enable="NO"

10. List Network Sockets

In order to display a list of open ports in FreeBSD use the sockstat command.

List all IPv4 network sockets on FreeBSD.

# sockstat -4
List Ipv4 Ports on FreeBSD

List Ipv4 Ports on FreeBSD

Display all IPv6 network sockets on FreeBSD.

# sockstat -6
List Ipv6 Ports on FreeBSD

List Ipv6 Ports on FreeBSD

You can combine the two flags to display all network sockets as illustrated in the below screenshot.

# sockstat -4 -6
List FreeBSD Open Ports

List FreeBSD Open Ports

List all connected sockets on FreeBSD.

# sockstat -c
List Connected Sockets on FreeBSD

List Connected Sockets on FreeBSD

Display all network sockets in listening state and Unix domain sockets.

# sockstat -l
List Listening Sockets on FreeBSD

List Listening Sockets on FreeBSD

Other than sockstat utility, you can run netstat or lsof command to display system and network sockets as well.

lsof utility is not installed in FreeBSD by default. To install it from FreeBSD ports repositories issue the following command.

# pkg install lsof

To display all IPv4 and IPv6 network sockets with lsof command, append the following flags.

# lsof -i4 -i6
List Sockets Using lsof Command

List Sockets Using lsof Command

In order to display all network sockets in listening state on FreeBSD with netstat utility, issue the following command.

# netstat -an |egrep 'Proto|LISTEN'

Or run the command without -n flag in order to display the name of the opened sockets in listening state.

# netstat -a |egrep 'Proto|LISTEN'
List Listening Sockets Using Netstat

List Listening Sockets Using Netstat

These are just a few basic utilities and commands you need to know in order to manage a FreeBSD system on daily basis.

FreeBSD 11.1 Installation Guide

FreeBSD is a free, powerful, robust, flexible and stable Open Source operating system based on Unix which is designed with security and speed in mind.

FreeBSD can operate on a large variety of modern CPU architectures and can power servers, desktops and some kind of custom embedded systems, the most notable being Raspberry PI SBC. As in Linux case, FreeBSD comes with a large collection of pre-compiled software packages, more than 20,000 packages, that can be simply installed in the system from their repositories, called “Ports”.

Requirements:

  1. Download FreeBSD 11.1 CD 1 ISO Image

This tutorial will guide you on how to install the latest version of FreeBSD on an amd64 machine. Typically this installation covers only the command line version of the operating system, which makes it best-suited for servers.

If you don’t require a custom installation, you can skip the installation process and download and run a pre-build Virtual Machine image for VMware, VirtualBox, QEMU-KVM or Hyper-V.

FreeBSD Installation Guide


1. First, get the latest FreeBSD CD 1 ISO image released from FreeBSD download page and burn it to a CD.

Place the CD image into your machine CD/DVD drive and reboot the machine into BIOS/UEFI mode or boot menu sequence by pressing a special key (usually esc, F2, F11, F12) during the power-on sequence.

Instruct the BIOS/UEFI to use the CD/DVD appropriate drive to boot from and the first screen of the installation process should be displayed on your screen.

Press [Enter] key to start the installation process.

FreeBSD Grub Menu

FreeBSD Grub Menu

2. On the next screen select Install option and press [Enter] to continue.

FreeBSD Installer

FreeBSD Installer

3. Select your keyboard layout from the list and press [Enter] to move forward with the installation process.

FreeBSD Keyboard Layout

FreeBSD Keyboard Layout

4. Next, type a descriptive name for your machine hostname and press [Enter] to continue.

FreeBSD Machine Hostname

FreeBSD Machine Hostname

5. On the next screen select what components you want to install in the system by pressing the [space] key. For a production server it’s recommended you choose only lib32 compatibility libraries and Ports tree.

Press [enter] key after you’ve made your selections in order to continue.

FreeBSD Components

FreeBSD Components

6. Next choose the method your hard disk will be partitioned. Select Auto – Unix File SystemGuided Disk Setup and press [enter] key to move to the next screen.

In case you have more than one disk and need a resilient file system you should opt for ZFS method. However, this guide will only cover UFS file system.

FreeBSD Partitioning

FreeBSD Partitioning

7. On the next screen select to perform FreeBSD OS installation on the entire disk and press [enter] key again to continue.

However, be aware that this option is destructive and will completely wipe-out all your disk data. If the disk holds data, you should make a backup before continuing further.

FreeBSD Installation Disk

FreeBSD Installation Disk

8. Next, select you hard disk partition layout. In case your machine is UEFI based and the installation is performed from UEFI mode (not CSM or Legacy mode) or the disk is larger than 2TB, you must use GPT partition table.

Also, it’s recommended to disable Secure Boot option from UEFI menu if the installation is performed in UEFI mode. In case of an older hardware you’re safe to partition the disk in MBR scheme.

FreeBSD Partition Layout

FreeBSD Partition Layout

9. In the next screen review the automatically created partition table of your system and navigate to Finish using [tab] key to accept the changes.

Press [enter] to continue and on the new pop-up screen select Commit to start the effective installation process. The installation process can take up from 10 to 30 minutes depending on your machine resources and HDD speed.

FreeBSD Partition Summary

FreeBSD Partition Summary

FreeBSD Installation Changes

FreeBSD Installation Changes

FreeBSD Installation Progress

FreeBSD Installation Progress

FreeBSD Installation Continues

FreeBSD Installation Continues

10. After the installer extracts and writes the operating system data to your machine drive, you will be prompted to specify the password for the root account.

Choose a strong password for root account and press [enter] to continue. The password won’t be echoed on the screen.

FreeBSD Root Password

FreeBSD Root Password

11. On the next step, select the network interface you want to configure and press [enter] to setup the NIC.

FreeBSD Network Configuration

FreeBSD Network Configuration

12. Choose to use IPv4 protocol for your NIC and select to configure the network interface manually with a static IP address by negating the DHCP protocol as illustrated in the below screenshots.

FreeBSD IPv4

FreeBSD IPv4

FreeBSD DHCP

FreeBSD DHCP

13. Next, add your static network IP configurations (IP address, netmask and gateway) for this interface and press [enter] key to continue.

FreeBSD IP Configuration

FreeBSD IP Configuration

14. If the network equipment at your premises (switches, routers, servers, firewalls etc) is IPv4 based then is no point on configuring IPv6 protocol for this NIC. Choose No from the IPv6 prompt to continue.

FreeBSD IPv6 Disable

FreeBSD IPv6 Disable

15. The final network configuration for your machine involves setting-up the DNS resolver. Add your domain name for local resolving, if that’s the case, and the IP addresses of two DNS servers you run in your network, used for resolving domain names, or use the IP addresses of some public DNS caching servers. When you finish, press OK to save changes and move further.

FreeBSD DNS Configuration

FreeBSD DNS Configuration

16. Next, from the time zone selector choose the physical region where your machine is located and hit OK.

FreeBSD Timezone

FreeBSD Timezone

17. Select your country from the list and accept the abbreviation for your time setting.

FreeBSD Country Selection

FreeBSD Country Selection

18. Next, adjust the date and time setting for your machine if that’s the case or choose to Skip the setting in case your system time is correctly configured.

FreeBSD Time and Date Settings

FreeBSD Time and Date Settings

FreeBSD Set Date

FreeBSD Set Date

19. On the next step select by hitting the [space] key the following daemons to run system-wide: SSH, NTP and powerd.

Select powerd service in case your machine CPU supports adaptive power control. If FreeBSD is installed under a virtual machine you can skip powerd start-up service during the system boot initialization sequence.

Also, if you don’t connect into your machine remotely, you can skip SSH service automatic start-up during system boot. When you finish press OK to continue.

FreeBSD System Configuration

FreeBSD System Configuration

20. At the next screen, check the following options in order to minimally harden your system security: Disable reading kernel message buffer for unprivileged users, Disable process debugging facilities for unprivileged users, Clean /tmp filesystem on startup, Disable Syslogd network socket and Sendmail service in case you’re not planning to run a mail server.

FreeBSD System Hardening

FreeBSD System Hardening

21. Next, the installer will ask you whether you will like to add a new system user. Choose yes and follow the prompt in order to add the user information. It’s safe to leave the default settings for the user by pressing [enter] key.

You can select Bourne shell (sh) or C improved shell (tcsh) as the default shell for your user. When you finish, answer yes at the final question to create the user.

The prompt will ask you if you want to add another user in your system. If that’s not the case, answer with no in order to continue with the final stage of the installation process.

FreeBSD User Account

FreeBSD User Account

Create FreeBSD User Account

Create FreeBSD User Account

FreeBSD User Account Summary

FreeBSD User Account Summary

22. Finally, a new screen will provide a list of options you can choose in order to modify your system configuration. If you have nothing else to modify on your system, select the Exit option in order to complete the installation and answer with no to not open a new shell in the system and hit on Reboot to restart the machine.

FreeBSD Final Configuration

FreeBSD Final Configuration

FreeBSD Manual Configuration

FreeBSD Manual Configuration

FreeBSD Installation Complete

FreeBSD Installation Complete

23. Remove the CD image from the machine drive and press [enter] at the first prompt to start the system and logon into the console.

FreeBSD Login Shell

FreeBSD Login Shell

Congratulations! You’ve just installed FreeBSD operating system in your machine. In the next tutorial we’ll discuss some initial configurations of FreeBSD and how to manage the system further from command line.

How to Rename File While Downloading with Wget in Linux

Wget utility is a popular and feature-rich command-line based file downloader for Unix-like operating systems and Windows OS. It supports non-interactive downloading of files over protocols such as HTTP, HTTPS, and FTP.

It’s designed to work reliably with slow or unstable network connections. Importantly, in case of network disruptions, it enables you to continue getting a partially-downloaded file by running a particular command again.

Suggested Read: 5 Linux Command Line Based Tools for Downloading Files

In this short article, we will explain how to rename a file while downloading with wget command on the Linux terminal.

By default, wget downloads a file and saves it with the original name in the URL – in the current directory. What if the original file name is relatively long as the one shown in the screen shot below.

$ wget -c https://gist.github.com/chales/11359952/archive/25f48802442b7986070036d214a2a37b8486282d.zip
Wget Download File

Wget Download File


Taking the example above, to rename the downloaded file with wget command to something else, you can use the -O or --output-document flag with the -c or --continue options helps to continue getting a partially-downloaded file as we explained at the start.

$ wget -c https://gist.github.com/chales/11359952/archive/25f48802442b7986070036d214a2a37b8486282d.zip -O db-connection-test.zip
Wget Rename Download File

Wget Rename Download File

Note that -O flag tells wget to perform shell redirection other than instructing it to use the new name instead of the original name in the URL. This is what practically happens:

$ wget -cO - https://gist.github.com/chales/11359952/archive/25f48802442b7986070036d214a2a37b8486282d.zip > db-connection-test.zip
$ ls
Wget - Rename File While Downloading

Wget – Rename File While Downloading

The file is written to standard output and then redirected by the shell to the specified file as shown in the screen shot above.

If you want to download videos from You-tube and other sites from the command line, you can install and use YouTube-DL in Linux.

That’s all for now! In this article, we showed how to rename the downloaded file with wget command. To send us any queries or add your thoughts to this article, use the comment form below.

How to Boot into Single User Mode in CentOS/RHEL 7

Single User Mode (sometimes known as Maintenance Mode) is a mode in Unix-like operating systems such as Linux operate, where a handful of services are started at system boot for basic functionality to enable a single superuser perform certain critical tasks.

It is runlevel 1 under system SysV init, and runlevel1.target or rescue.target in systemd. Importantly, the services, if any, started at this runlevel/target varies by distribution. It’s generally useful for maintenance or emergency repairs (since it doesn’t offer any network services at all), when a computer is not capable of normal operations.

Some of the low-level repairs include running such as fsck of damaged disk partitions, reset root password if you have lost it, fix “failed to mount /etc/fstab” error – just to mention the most critical of them. And also when the system fails to boot normally.

In this tutorial, we will describe how to boot into single user mode on CentOS 7. Note that practically this will help you enter the emergency mode and access an emergency shell.

How to Boot into Single User Mode


1. First restart your CentOS 7 machine, once boot process starts, wait for the GRUB boot menu to appear as shown in the screen shot below.

CentOS 7 Grub Menu

CentOS 7 Grub Menu

2. Next, select your Kernel version from the grub menu item and press e key to edit the first boot option. Now use the Down arrow key to find the kernel line (starts with “linux16“), then change the argument ro to rw init=/sysroot/bin/sh as shown in the screen shot below.

Edit Grub Boot Options

Edit Grub Boot Options

3. Once you have finished the task in the previous step, press Ctrl-X or F10 to boot into single user mode (access an emergency shell).

CentOS 7 Emergency Shell

CentOS 7 Emergency Shell

4. Now mount root (/) filesystem using the following command.

# chroot /sysroot/

At this point, you can perform all the necessary low-level system maintenance tasks. Once you are done, reboot the system using this command.

# reboot -f

You may also liked to read following articles.

  1. How to Hack Your Own Linux System
  2. Linux Directory Structure and Important Files Paths Explained
  3. How to Create and Run New Service Units in Systemd Using Shell Script
  4. How to Manage ‘Systemd’ Services and Units Using ‘Systemctl’ in Linux

Lastly, the single user mode or maintenance mode is not password-protected by default, so any one with malicious intend and physical access to your computer can enter the emergency mode and “destroy” your system.

Next, we will show you how to password-protect single user mode on CentOS 7. Until then, stay connected to Tecmint.com.

How to Change Runlevels (targets) in SystemD

‘,
enableHover: false,
enableTracking: true,
buttons: { twitter: {via: ‘tecmint’}},
click: function(api, options){
api.simulateClick();
api.openPopup(‘twitter’);
}
});
jQuery(‘#facebook’).sharrre({
share: {
facebook: true
},
template: ‘{total}’,
enableHover: false,
enableTracking: true,
click: function(api, options){
api.simulateClick();
api.openPopup(‘facebook’);
}
});
jQuery(‘#googleplus’).sharrre({
share: {
googlePlus: true
},
template: ‘{total}’,
enableHover: false,
enableTracking: true,
urlCurl: ‘https://www.tecmint.com/wp-content/themes/tecmint/js/sharrre.php’,
click: function(api, options){
api.simulateClick();
api.openPopup(‘googlePlus’);
}
});
jQuery(‘#linkedin’).sharrre({
share: {
linkedin: true
},
template: ‘{total}’,
enableHover: false,
enableTracking: true,
buttons: {
linkedin: {
description: ‘How to Change Runlevels (targets) in SystemD’,media: ‘https://www.tecmint.com/wp-content/uploads/2017/08/Change-Runlevels-Targets-in-Systemd.png’ }
},
click: function(api, options){
api.simulateClick();
api.openPopup(‘linkedin’);
}
});
// Scrollable sharrre bar, contributed by Erik Frye. Awesome!
var shareContainer = jQuery(“.sharrre-container”),
header = jQuery(‘#header’),
postEntry = jQuery(‘.entry’),
$window = jQuery(window),
distanceFromTop = 20,
startSharePosition = shareContainer.offset(),
contentBottom = postEntry.offset().top + postEntry.outerHeight(),
topOfTemplate = header.offset().top;
getTopSpacing();
shareScroll = function(){
if($window.width() > 719){ var scrollTop = $window.scrollTop() + topOfTemplate,
stopLocation = contentBottom – (shareContainer.outerHeight() + topSpacing);
if(scrollTop > stopLocation){
shareContainer.offset({top: contentBottom – shareContainer.outerHeight(),left: startSharePosition.left});
}
else if(scrollTop >= postEntry.offset().top-topSpacing){
shareContainer.offset({top: scrollTop + topSpacing, left: startSharePosition.left});
}else if(scrollTop 1024)
topSpacing = distanceFromTop + jQuery(‘.nav-wrap’).outerHeight();
else
topSpacing = distanceFromTop;
}
});
]]>

GNOME at 20: Four reasons it's still my favorite GUI

The GNOME desktop turns 20 on August 15, and I’m so excited! Twenty years is a major milestone for any open source software project, especially a graphical desktop environment like GNOME that has to appeal to many different users. The 20th anniversary is definitely something to celebrate!

Why is GNOME such a big deal? For me, it’s because it represented a huge step forward in the Linux desktop. I installed my first Linux system in 1993. In the early days of Linux, the most prevalent graphical environment was TWM, the tabbed window manager. The modern desktop didn’t exist yet.

But as Linux became more popular, we saw an explosion of different graphical environments, such as FVWM (1993) and FVWM95 (1995), and their derivatives, including Window Maker (1996), LessTif (1996), Enlightenment (1997), and Xfce (1997). Each filled a different niche. Nothing was integrated. Rather, FVWM and its clones simply managed windows. Toolkits were not standardized; each window might use a different one. As a result, early Linux graphical environments were a mishmash of various styles. Window Maker offered the most improvements, with a more uniform look and feel, but it still lacked the integration of a true desktop.

I was thrilled when the GNOME project released a true Linux desktop environment in 1999. GNOME 1 leveraged the GTK+ toolkit, the same object-oriented widget toolkit used to build the GIMP graphics program.

The first GNOME release looked very similar to Windows 98, the then-current version of Microsoft Windows, a wise decision that immediately provided a familiar graphical interface for new Linux users. GNOME 1 also offered desktop management and integration, not simply window management. Files and folders could be dropped on the desktop, providing easy access. This was a major advancement. In short order, many major Linux distributions included GNOME as the default desktop. Finally, Linux had a true desktop.

Over time, GNOME continued to evolve. In 2002, GNOME’s second major release, GNOME 2, cleaned up the user interface and tweaked the overall design. I found this quite invigorating. Instead of a single toolbar or panel at the bottom of the screen, GNOME 2 used two panels: one at the top of the screen, and one at the bottom. The top panel included the GNOME Applications menu, an Actions menu, and shortcuts to frequently used applications. The bottom panel provided icons of running programs and a representation of the other workspaces available on the system. Using the two panels provided a cleaner user interface, separating “things you can do” (top panel) and “things you are doing” (bottom panel).

I loved the GNOME 2 desktop, and it remained my favorite for years. Lots of other users felt the same, and GNOME 2 became a de facto standard for the Linux desktop. Successive versions made incremental improvements to GNOME’s user interface, but the general design concept of “things you can do” and “things you are doing” remained the same.

Despite the success and broad appeal of GNOME, the GNOME team realized that GNOME 2 had become difficult for many to use. The applications launch menu required too many clicks. Workspaces were difficult to use. Open windows were easy to lose under piles of other application windows. In 2008, the GNOME team embarked on a mission to update the GNOME interface. That effort produced GNOME 3.

GNOME 3 removed the traditional task bar in favor of an Overview mode that shows all running applications. Instead of using a launch menu, users start applications with an Activities hot button in the black bar at the top. Selecting the Activities menu brings up the Overview mode, showing both things you can do (with the favorite applications launcher to the left of the screen), and things you are doing (window representations of open applications).

Since its initial release, the GNOME 3 team has put in a lot of effort to improve it and make it easier to use. Today’s GNOME is modern yet familiar, striking that difficult balance between features and utility.

4 reasons GNOME is my favorite GUI

Here at GNOME’s 20th anniversary, I’d like to highlight four reasons why GNOME 3 is still my favorite desktop today:

1. It’s easy to get to work

GNOME 3 makes it easy to find my most frequently used applications in the favorite applications launcher. I can add my most-used applications here, so getting to work is just a click away. I can still find less frequently used applications in the Applications menu, or I can just start typing the name of the program to quickly search for the application.

2. Open windows are easy to find

Most of the time, I have two or three windows open at once, so it’s easy to use Alt+Tab to switch among them. But when I’m working on a project, I might have 10 or more windows open on my desktop. Even with a large number of open applications, it’s straightforward to find the one that I want. Move the mouse to the Activities hot corner, and the desktop switches to Overview mode with representations of all your open windows. Simply click on a window, and GNOME puts that application on top.

3. No wasted screen space

With other desktop environments, windows have a title bar with the name of the application, plus a few controls to minimize, maximize, and close the window. When all you need is a button to close the window, this is wasted screen space. GNOME 3 is designed to minimize the decorations around your windows and give you more screen space. GNOME even locates certain Action buttons in the window’s title bar, saving you even more space. It may not sound like much, but it all adds up when you have a lot of open windows.

4. The desktop of the future

Today, computers are more than a box with a monitor, keyboard, and mouse. We use smartphones and tablets alongside our desktop and laptop computers. In many cases, mobile computing (phones and tablets) displaces the traditional computer for many tasks. I think it’s clear that the mobile and desktop interfaces are merging. Before too long, we will use the same interface for both desktop and mobile. The key to making this work is a user interface that truly unifies the platforms and their unique use cases. We aren’t quite there yet, but GNOME 3 seems well positioned to fill this gap. I look forward to seeing this area develop and improve.