Archive | Aralık, 2017

Install, Configure, and Troubleshoot Linux Web Server

In this post, we will talk about Linux web server and how to install it and configure it to serve you content to others. A web server is a system that manipulates requests via HTTP protocol, you request a file from the server and it responds with the requested file, which might give you an idea that web servers are only used for the web. Actually, web servers can also be found embedded in devices such as printers, routers, when you open your router configuration page, there is a web server behind it. When you open the printer configuration page, there is also a web server behind it serving your requests, so web servers are important today because they are used everywhere. First, your browser sends a request to the server. The server takes the requested file or page from you and maps it to the corresponding file from the server. The server sends the file back to the browser with some information such as its MIME type, the length of the content and some other useful information.

Continue Reading →

Sometimes the requested file is a static page like HTML pages or dynamic pages like PHP, Java, Perl or any other server side language. For example, when you type www.yourDomain.com, the browser queries the DNS server about the IP address of the computer: www.yourDomain.com. Once the browser gets the response from the DNS, it starts a TCP connection on port 80 and asks for the default web page, then this page is sent to you and that’s all.

Linux Webserver Implementations

There are many Linux web server implementations available for you to use:

  • Apache server
  • Nginx
  • Lighttpd
  • Apache Tomcat
  • Monkey HTTP Daemon (used especially for embedded systems)

There are more Linux web servers, but this list is the most used web servers.

The most used web servers are Apache and Nginx.

In this post, we will use Apache server for several reasons:

  • It is stable.
  • It is flexible.
  • It is secure.

We’ll install and configure Apache server on Linux, but at first, let’s review some of the basics of HTTP protocol basics.

Understanding HTTP

When you request a file or a page from a web server, the client at first connects to the server on port 80. After successful connection, the client then sends HTTP commands (also methods) to the server. This command includes a request header which includes information about the client.

To view these request headers in chrome, open chrome devtools, then open network panel and visit google.com and check the request headers, you should see something like this:

Linux Web Server Request Header

The request header also includes information about the client, like the user agent and the accepted formats.

Additional information may be sent with the request header. For example, if you click on a link that will open another website, the header will include the referral site.

After receiving the request header completely, the server responds with the requested file or page along with a response header.

The response header includes information about the received content, its type, and other information.

Linux Web Server response header

You can check the response headers from the browser network panel.

Install Apache Webserver

You can install Apache server on Red Hat based distros using the following command:

$ dnf -y httpd

Or if you are using a Debian-based distro, you can install it like this:

$ apt-get -y install apache2

The Apache web server service is called httpd on Red Hat based distros like CentOS, while it is called apache2 in Debian based distros.

If you are using a firewall like iptables, you should add a rule for port 80.

$ iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

Or if you are using firewalld, you can use the following command:

$ firewall-cmd --add-port=80/tcp

To start your service and enable it on boot:

$ systemctl start httpd

$ systemctl enable httpd

You can check if your service is running or not, using the following command:

$ systemctl status httpd

You can check if your service is running or not, using the following command:

$ systemctl status httpd

Now open your browser and visit http://localhost or http://[::1]/ if you are using IP v6 and if your installation goes well, you should see your HTML homepage.

Configuring Apache Webserver

You can add files to Apache in the /var/www/html directory for top-level pages.

Just remember to make sure that any files or directories placed in that directory are world-readable.

The default index page is index.html.

The Apache configuration files are in  /etc/httpd/conf/ directory.

On Debian based systems like Ubuntu, you may find it at  /etc/apache2/apache2.conf file.

We can’t discuss every option for Apache on a single post, but we will discuss the most important options.

You call them options or directives.

ServerRoot Option

This option specifies the configuration folder for Apache web server. On Red Hat based distros, the ServerRoot option is /etc/httpd/ directory. On Debian distros the ServerRoot option is /etc/apache2/.

ServerRoot /etc/httpd

Listen Option

This is the port that Apache web server will use to wait for incoming connections.

The default value for this option is 80 for nonsecure connections and 443 for secured connections.

If you have multiple IP addresses on your server, you can assign which IP should listen for connection using Listen option.

You can specify a different port other than 80, just make sure that it’s not in use.

You can run many HTTP servers on the same hardware every one on a unique port.

When a server runs on a non-standard port such as port 8080, it will require the port number to be explicitly stated like this:

www.example.com:8080

Listen 80

ServerName Option

This option specifies the hostname of the web server that appears to the visitors.

ServerName FQDN

DocumentRoot Option

This defines the path that will contain your files that will be served.

The default path is /var/www/html .

DocumentRoot /var/www/html

MaxRequestWorkers Option

This option sets the maximum number of concurrent connections that the server will receive.

LoadModule Option

This option is used to load modules into Apache web server.

There are a lot of Apache modules like these:

mod_cgid: This module is used to run CGI scripts using Apache web server.

mod_ssl: Provides secure connections via SSL and TLS protocols.

mod_userdir: This module allows you to serve content from users specific directories.

If you want to disable loading a specific module, you can comment the Load module line that contains that module.

Or if you use Debian based distros like Ubuntu, you can use these commands:

$ a2enmod modulename

This command to enable the module.

$ a2dismod modulename

This command to disable the module.

All these commands do is create a symlink under /etc/apache2/modsenabled  directory with the file that contains the module you want to enable. All files under this directory are included in Apache configuration by default, so any file will exist in this directory will be included.

And if you use a2dismod, the symlink will be removed.

If you enable or disable a module, you have to reload or restart apache web server.

LoadModule mod_cgid.so

Include Option

This option allows you to include other configuration files.

You can store all the configuration for different virtual domains, and Apache will include them at runtime.

Include filePath

UserDir option

This option specifies the directory that will contain the files that will be accessible via the web server. This directory is usually named public_html and its location in user’s home directory.

For example, if you have a user adam who wants to make his web content available via Apache web server.

First, we make a public_html folder under his home directory.

Then set the permission for the public_html folder:

$ chmod 644 public_html

Now if we put an index.html file, it will be accessible via the browser like this:

http://YOURHOSTNAME/~adam

UserDir public_html

Alias Option

This option specifies the location of the files that are outside the DocumentRoot location and need to be served by the Apache web server.

Like you have files outside DocumentRoot and you want them to be available to the visitors.

Alias URL_Path Actual_Path

ErrorLog Option

This option specifies the error log file for Apache web server.

ErrorLog /var/log/httpd/error_log

VirtualHost Option

This option allows you to host multiple websites on the same server.

The idea is that the content is served based on the requested hostname.

To setup a virtual host for the host www.example.com. First, create a VirtualHost option in /etc/httpd/conf/httpd.conf file.

And specify the DocumentRoot and ServerName like this:

ServerAdmin admin@example.com

DocumentRoot /home/adam/public_html

ServerName www.example.com

ErrorLog /var/log/users/adam/error_log

</VirtualHost>

Keep in mind that the ServerName option must be resolvable via DNS.

These are the most used Apache options.

Virtual Host Types

There are two types of virtual hosts that you can define in Apache web server:

  • Name-based virtual hosts
  • IP-based virtual hosts

The NameVirtualHost directive defines which addresses can be virtual hosts; the asterisk (*) means any name or address on this server. You can write them like this:

NameVirtualHost *
<VirtualHost *>
ServerName www.example.com
DocumentRoot “/home/user1/public_html/”
</VirtualHost>
<VirtualHost *>
ServerName www.example2.com
DocumentRoot “/ home/user2/public_html/”
</VirtualHost>

If you have more than one IP address and you want to use SSL certificate, the website must be on a dedicated IP address. You can write IP-based virtual hosts like this:

<VirtualHost 192.168.1.2>
ServerName www.example.com
DocumentRoot “/home/user1/public_html/”
</VirtualHost>
<VirtualHost 192.168.1.3>
ServerName www.example2.com
DocumentRoot “/ home/user2/public_html/”
</VirtualHost>

Apache Process Ownership

We know from the Linux process management that each process inherits its permissions of its parent process.

This fact is true for all processes except for applications with the SETUID bit set, they inherit permissions from the owner, not the parent process. A good example is the /bin/su.

If a normal user runs /bin/su program, it does not inherit the permission from adam, but it acts as a root user running it.

Since Apache web server needs to bind port 80, and this needs root privileges.

After binding to port 80, Apache can run as a normal user and read only files that have permissions to read them.

Based on the Linux distro you use, the user could be one of the following:

nobody, www, apache, www-data, or daemon.

I delayed introducing two more options for apache till reaching that point.

User Option

This specifies the user ID which the web server will use to answer requests.

User wwwdata

Group Option

This specifies the group that Apache web server will use to read files.

Group wwwdata

Security is very important for sites that use executable scripts such as CGI or PHP scripts.

The use that you will use will have permission to read and write the content of all sites on the server. But we want to ensure that only the members of a particular site can read their own site only.

This is very important because if a site got compromised, the attacker will be able to read all files since the apache user has permission to do that.

So how to solve this problem?

suEXEC Support

A popular method is to use suEXEC. suEXEC is a program that runs with root permissions and makes CGI programs run as the user and group IDs of a specific user, not the Apache server user.

You can specify the user on each virtual host like this:

<VirtualHost www.example.com>

SuExecUserGroup adam adamGroup

</VirtualHost>

Just that simple.

Apache Authentication

You may want to restrict some parts to specific visitors. It’s like a password protected directory.

In Apache, you can store authentication information file called .htpasswd file.

You can use the htpasswd command to do that.

First, create the .htpasswd file using the htpasswd command:

$ htpasswd -c /home/adam/.htpassswd myuser

The -c option is needed the first time you run htpasswd, but when you need to add more users you shouldn’t use -c because it will overwrite the file.

Then create a .htaccess file in the public_html folder and write the following:

<Location /vip>

AuthName "test"

AuthType Basic

AuthUserFile /home/adam/.htpasswd

Order deny,allow

require valid-user

</Location>

AuthName is required, you can use any string you want.

AuthType Basic says that you’re using htpasswd style user file.

AuthUserFile points to the file that contains the generated password from htpasswd command.

The Order line indicates that Apache must deny access by default, and only allow access for users specified in the htpasswd file.

The require directive means any user in the .htpasswd file is allowed.

Troubleshooting Apache Webserver

If you modify the httpd.conf file and restart or reload Apache web server and it did not work, then you have typed a wrong configuration, however, this is not the only case that you need to troubleshoot Apache, you may look at the apache logs to see how the service works so you can diagnose the problem and solve it.

The two main log files for apache are error_log and access_log files.

You can find these files in /var/log/httpd/  directory in Red Hat based distros, or in /var/log/apache2/  directory if you are using Debian based distros.

The access_log file contains every request to Apache web server with the details about client requested that resource.

The error_log file contains errors of Apache web server.

You can use tail command to watch the log file:

$ tail -f /var/log/httpd/error_log

I recommend you to review the Linux syslog server to know more about logging.

I hope you find working with Linux web server easy and interesting. Keep coming back.

Thank you.

likegeeks.com

0

Antergos 17.12 duyuruldu

Arch tabanlı bir dağıtım olan Antergos’un güncelleştirilmiş bir sistem yükleyicisi içeren 17.12 sürümü duyuruldu. Live ve minimal ortamlar için güncellenen paketlerle gelen sistemin live sürüm ve minimal sürüm olarak iki ayrı kalıp olarak indirilebileceği söylenirken, minimal sürüm olarak kullanıma sunulan kalıbın 635 MB boyutlarına kadar küçültülmüş olduğu ifade edildi. Live ve minimal versiyonlar için tüm paketlerin güncelleştirildiği belirtildi. Antergos 17.12 hakkında ayrıntılı bilgi edinmek için sürüm duyurusunu inceleyebilirsiniz.

Continue Reading →

Antergos 17.12 edinmek için aşağıdaki linkten yararlanabilirsiniz.

0

Rocks Cluster 7.0 duyuruldu

Beta sürümü 10 Eylül 2017‘de duyurulan CentOS tabanlı açık kaynak kodlu bir küme çözümü olan Rocks Cluster‘in “Manzanita” kod adlı 7.0 sürümü, Philip Papadopoulos tarafından duyuruldu. CentOS 7.4’e dayalı olarak gelen sistem, 1 Aralık 2017 itibariyle tüm güncelleştirmeleri içeriyor. Rocks 6’dan önemli ölçüde farklı olan yeni sürüm, yalnızca ağa kurulumu destekliyor. Papadopoulos; Rocks Cluster’in (PBS, Maui, GM desteği, Ganglia, vb. gibi) herhangi bir kümeleme yazılım yığınından kurulumun sadeliğinde benzersiz olmasıyla ayrıldığını söyledi. Sürüm duyurusu, sürüm hakkında pek fazla bilgi içermese de Rocks Cluster 7.0 hakkında ayrıntılı bilgi edinmek için kullanım kılavuzunu inceleyebilirsiniz.

Continue Reading →

Rocks Cluster 7.0 edinmek için aşağıdaki linklerden yararlanabilirsiniz.

0

GNU GLPK 4.64 duyuruldu

GNU Projesinin bir parçası olan ve GNU Genel Kamu Lisansı ile lisanslı olan GNU GLPK‘nin 4.64 sürümü, Andrew Makhorin tarafından duyuruldu. GLPK (GNU Linear Programming Kit – doğrusal programlama seti); büyük ölçekli doğrusal programlamayı (LP), karışık tam sayı programlamayı (MIP) ve diğer ilgili sorunları çözmek için tasarlanmış bulunuyor. GLPK; AMPL dilinin bir alt kümesi olan GNU MathProg modelleme dilini destekliyor. GLPK ayrıca bir C kütüphanesi olarak da kullanılabiliyor. OptimJ modelleme sisteminin özgür sürümünde de desteklenen GLPK’ye bağımsız bir proje, JNI, Java tabanlı bir arabirim sağlıyor. GNU GLPK 4.64 hakkında ayrıntılı bilgi edinmek için sürüm duyurusunu inceleyebilirsiniz.

Continue Reading →

GNU GLPK 4.64 edinmek için aşağıdaki linklerden yararlanabilirsiniz.

0

GNU Guile 2.2.3 duyuruldu

Programcıların esnek uygulamalar oluşturmasına yardımcı olan GNU Guile‘nin 2.2.3 sürümü, Andy Wingo tarafından duyuruldu. GNU Guile 2.2.3’ü duyurmaktan memnuniyet duyduklarını ifade eden geliştirici ekip, bunun bir hata düzeltme sürümü olduğunu ve kimi problemleri giderdiğini belirtti. Özellikle büyük Scheme dosyaları üzerinde daha hızlı çalışan derleyicide, artık REPL içine çok satırlı bir ifade yapıştırılmasının olanaklı olduğu ifade ediliyor. Kullanıcılar tarafından genişletilebilen ya da diğer programcıların eklentilerini, modüllerini veya komut dosyalarını kullanıma sokan GNU Guile ile masaüstü ortamları, web, komut satırı ve daha fazlası için için çeşitli uygulamalar veya oyunlar yaratmak mümkündür. Scheme programlama dilinin bir uygulaması olan GNU Guile, Revised5 ve Revised6 dil raporlarının çoğunu ve SRFI’yi destekler. XML ayrıştırma tekniği ve nesne yönelimli programlama yetisi sunan GNU Guile, bir HTTP sunucusu ve istemci gibi ek özellikler sunan bir modül kütüphanesi ile birlikte gelir. Kolaylıkla C ve C ++ programlarıyla entegre edilebilen GNU Guile, GNU Projesi tarafından GNU Lesser General Public lisansı altında kullanıma sunuluyor. GNU Guile 2.2.2 hakkında geniş bilgi edinmek için sürüm duyurusunu inceleyebilirsiniz.

Continue Reading →

GNU Guile 2.2.3 edinmek için aşağıdaki linklerden yararlanabilirsiniz.

0

Install, Configure, and Secure FTP Server in Linux

FTP or File Transfer Protocol is a commonly used protocol for transferring files between computers, one act as a client, the other act as a server. In this post, we will talk about the FTP server in Linux systems, specifically Very Secure FTP Daemon (vsftpd). The vsftpd program is a very popular FTP server that is used by many servers today. FTP server works with the client server architecture to communicate and transfer files. FTP is a stateful protocol, that means connections between clients and servers stay open during an FTP session. To send or receive files from an FTP server, you can use FTP commands, these commands are executed consecutively. It is like a queue, one by one.

Continue Reading →

There are two types of FTP connections initiated:

  • Control connection also called a command connection.
  • Data connection.

When you establish an FTP connection, the TCP port 21 opens to send your login credentials, this connection is called control connection.

When you transfer a file, a data connection is started.

There are two types of data connection:

  • Passive mode.
  • Active mode.

Active connections are initiated by the remote server, and the client waits for server requests.

Passive connections initiated by the client to the remote server and the server waits for requests.

When the FTP client starts a transfer, there is an option on your FTP client that controls whether you want to use active or passive FTP connection.

Active Mode

The client connects from a random ephemeral source port to the FTP control port 21.

You can check your ephemeral port range using this command:

$ cat /proc/sys/net/ipv4/ip_local_port_range

When you need to transfer a file, the remote FTP server will open port 20 to connect to the FTP client.

Active mode connections usually have problems with firewalls, TCP ports 20 and 21 should be open on your firewall.

Because of these problems with firewalls of active mode, the passive mode was introduced.

If you are using iptables firewall I recommend you to review Linux iptables firewall to know how to allow specific ports.

Passive Mode

In passive mode, the client starts the control connection from a random port to the destination port 21 on the remote server.

if the FTP client requests a file, it will issue the PASV FTP command. The server will open a random port and give this port number to the client.

That’s why the FTP is a connection-hungry protocol because every time you make a data connection (like transfer a file) the server will do the above process and this is done with all clients connected to the server.

In passive mode, the control and data connections started by the FTP client.

Vsftpd FTP Server Features

There are several FTP servers available for you to use, commercial and open source.

Vsftpd has some security features which makes it on the top like:

  • Can run as a normal user with privilege separation.
  • Supports SSL/TLS FTP connections.
  • Can jail users into their home directories.

FTP Server Setup

Some Linux distros shipped with vsftpd, anyway, if you want to install it on Red Hat based systems, you can use the following command:

$ sudo dnf -y vsftpd

On Debian based distros like Ubuntu, you can install it like this:

$ sudo apt-get install vsftpd

Once you’ve installed the package, you can run the service and enable it to run at boot time.

$ systemctl start vsftpd

$ systemctl enable vsftpd

The configuration file for vsftpd FTP server is /etc/vsftpd/vsftpd.conf file or in Debian based distros, you can find it at /etc/vsftpd.conf .

Actually, the FTP server in Linux is one of the easiest servers that you can work with.

There are two types of accessing the FTP server:

  • Anonymous FTP access: anyone can login with the username anonymous without a password.
  • Local user login: all valid users on /etc/passwd are allowed to access the FTP server.

You can allow anonymous access to FTP server from the configuration, in /etc/vsftpd/vsftpd.conf by enabling anonymous_enable=YES if it is not enabled and reload your service.

Now you can try to connect to the FTP server using any FTP client, I will use the simple FTP command.

You can install it if it’s not on your system:

$ dnf -y install ftp

Now you can access your FTP server like this:

$ ftp localhost

Then type the username anonymous and with no password, just press enter.

You will see the FTP prompt.

ftp>

And now you can type any FTP command to interact with the FTP server.

Connect as Local User

Since there is an option in the settings for allowing local users to access FTP server which is local_enable=YES, now let’s try to access the FTP server using a local user:

$ ftp localhost

Then type your local username and the password for that user and you will see Login successful message.

Setup FTP Server as Anonymous Only

This kind of FTP server is useful if your files should be available for users without any passwords or login.

You need to configure vsftpd to allow only anonymous user.

Open /etc/vsftpd/vsftpd.conf file, and change the following options with the corresponding values.

listen=NO

listen_ipv6=NO

anonymous_enable=YES

local_enable=NO

write_enable=NO

Then we need to create a non-privileged system account to be used for anonymous FTP-type access.

$ useradd -c " FTP User" -d /var/ftp -r -s /sbin/nologin ftp

This user has no privileges on the system, so it is safer to use it when accessing an FTP server.

Don’t forget to restart your FTP server after you modify the configuration file.

You can access the FTP server from the browser, just type ftp://youdomain/

FTP Server Security

We can configure vsftpd to use TLS, so the transferred files over the network is a bit more secure.

First, we generate a certificate request using openssl command:

$ openssl genrsa -des3 -out FTP.key

Then we generate a certificate request:

$ openssl req -new -key FTP.key -out certificate.csr

Now we remove the password from the key file:

$ cp FTP.key FTP.key.orig

$ openssl rsa -in FTP.key.orig -out ftp.key

Finally, we generate our certificate:

$ openssl x509 -req -days 365 -in certificate.csr -signkey ftp.key -out mycertificate.crt

Now we copy the certificate file and the key and to /etc/pki/tls/certs:

$ cp ftp.key /etc/pki/tls/certs/

$ cp mycertificate.crt /etc/pki/tls/certs

Now, all we need to do is to configure vsftpd to support secure connections.

Open / etc/vsftpd/vsftpd.conf file and add the following lines:

ssl_enable=YES

allow_anon_ssl=YES

ssl_tlsv1=YES

ssl_sslv2=NO

ssl_sslv3=NO

rsa_cert_file=/etc/pki/tls/certs/mycertificate.crt

rsa_private_key_file=/etc/pki/tls/certs/ftp.key

ssl_ciphers=HIGH

require_ssl_reuse=NO

Restart your service to reflect these changes. And that’s it.

Try to connect to your FTP server from any client on any system like Windows and choose the secured connection or FTPS, and you will successfully see your folders.

SFTP vs. FTPS

In the last example, we saw the FTP over SSL layer (FTPS) and we’ve successfully connected to the FTP server, however, with the tightly secured firewall, it is difficult to manage this kind of connection since FTPS uses multiple port numbers.

The best solution, in this case, is to use SFTP (FTP over SSH).SFTP uses port 22 only.

This port is used for all connections during FTP sessions.

If you are using a firewall, it’s recommended to choose SFTP, since it needs only one port.

Jailing FTP Users

You can secure your FTP server by jailing your FTP users in their home directories and allow only specific users to access the service.

Open /etc/vsftpd/vsftpd.conf and uncomment the following options:

chroot_local_user=YES

chroot_list_enable=YES

chroot_list_file=/etc/vsftpd.chroot_list

The file /etc/vsftpd.chroot_list contains the list of jailed users one per line.

Save the files and restart your service.

$ systemctl restart vsftpd

Linux FTP Server Commands

You can use any GUI client to upload and download your files, but you need to know some FTP server commands also.

You can print the current working directory using pwd command:

ftp> pwd

You can list files using the ls command:

ftp> ls

Also, you can use the cd command to change the working directory:

ftp> cd /

If you want to exit your FTP session use the bye command:

ftp> bye

lcd command is used to display the local folder, not the FTP folder:

ftp> lcd

You can change the local directory using the lcd command:

ftp> lcd /home

You can download a file using the get command:

ftp> get myfile

Also, you can download multiple files using the mget command:

ftp> mget file1 file2

Use delete command to delete a file from the server:

ftp> delete filename

Use put command to upload a file to the server:

ftp> put filename

To upload multiple files, use the mput command:

ftp> mput file1 file2

You can create a directory using the mkdir command:

ftp> mkdir dirName

Or you can delete a directory from the server using the rmdir command.

ftp> rmdir dirName

There are two modes for file transfer when using FTP server, ASCII mode, and binary mode, you can change the mode like this:

ftp> binary

ftp> ascii

The FTP server is one of the easiest servers in Linux to configure and work with.

I hope you find the post useful and interesting. Keep coming back

Thank you.

likegeeks.com

0