This will be a series of posts about configuring a Linux server (I’m working with Ubuntu, but should work with minor changes with other distributions), mainly because I have done this several times now by reviewing different websites and blogs, so I wanted to do a guide that works for me (and maybe for others too).

First, we create a user to avoid the use of root (in case you are not using the default Ubuntu installation, that asks you to create a user):

$ adduser myuser
Adding user 'myuser' ...
Adding new group 'myuser' (1000) ...
Adding new user 'myuser' (1000) with group 'myuser' ...
Creating home directory '/home/myuser' ...
Copying files from '/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for myuser
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] y

It is also possible to use the command useradd (that is a linux command itself, not that user-friendly) instead of useradd (this one is a perl script that makes a little more easy user creation).

We need to assign add this user to the sudoers (users that are able to use the sudo command to make changes to the system).

$ visudo

And add the following line:

myuser  ALL=(ALL) ALL

Then, we need to hardening SSH server (be very careful about this modifications because if SSH is the only way you have to configure your server, any error may left you lock out of your box).

Before making any change, we better make a backup of our original config file:

$ cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bk

Then, we need to change the following parameters on /etc/ssh/sshd_config:

  • Port Number: Change it to any random port number, try to use one that any known service uses, see the list of services in here.
  • Listen Address: Instead of listen to every interface on your server, just listen to the main IP address.
  • Protocol: Make sure that this parameter is set to 2 (instead of 2, 1).
  • If possible, avoid root login by disabling PermitRootLogin. All root operations can be done using sudo command (at least on Debian/Ubuntu based distributions). Make sure you have created other users on your box, and add them to the allow list of users to log through SSH (AllowUsers [username1] [username2] parameter).
  • Disable X11Forwarding.
  • Replace password authentication with Public/Private Keys. To do this, make sure your users have their Private Keys and the Public Keys are configured on the server. Then, disable PasswordAuthentication and UsePAM parameters. Make sure that RSAAuthentication and Pubkeyauthentication parameters are enabled.
  • If you have noticed that OpenSSH server may take a while from the moment you enter your username and the password prompt, it is because it tries to make some DNS resolves. You can avoid this by disabling UseDNS parameter.

You should end with a file like this:

Port XXXX
ListenAddress XXX.XXX.XXX.XXX
[...]
PermitRootLogin no
[...]
RSAAuthentication yes
PubkeyAuthentication yes
[...]
PasswordAuthentication no
[...]
X11Forwarding no
[...]
UsePAM no
UseDNS no
AllowUsers myuser user2

Then, we need to restart the SSH server by doing:

$ /etc/init.d/ssh restart

Do not close your current session, just open another to your box using the new port, this way we make sure we are not locked out of it.

On the next post I will be configuring IPTables as a firewall for our box.

UPDATE 17/Apr/2010: Parameter PasswordAuthentication included for disabling keyboard-interactive authentication.

In this link you can find a very good explanation about the main options on SSH config file.

Tags: , , ,

I have noticed that my Ubuntu box is lately always trying to reach a SMTP server (detected through Wireshark tool). After reviewing the list of running processes that contains the word mail (running ps aux | grep mail on console), I found a couple of them called Nullmailer that seems the responsible of that and indeed, it was.

So a Google search led me to this thread, where in that case, Nullmailer registered entries on Syslog (which possible happened on my computer also). The messages that Nullmailer was trying to send were related to Cron jobs output. So, the solution was to delete the queue of messages of this program, located on /var/spool/nullmailer/queue/.

Tags: , , ,

If you use Clientexec as your hosting company’s management and support web application, and Google Apps for your emailing (or even just GMail), then, it is possible to configure Clientexec to send mails through Google SMTP server.

Unfortunately, it is not straightforward because the default Clientexec SMTP mailer (at least until 3.2.3 version of this software) can not handle SSL/TLS as Google required. You will need to manually modify the PHPMailer that is embedded on Clientexec.

The steps are not difficult, here they are:

First, open the file /{clientexec-directory}/newedge/classes/PHPMailer.php

Comment out the following part of the code (around line 537):

if(strstr($hosts[$index], ":"))
  list($host, $port) = explode(":", $hosts[$index]);

And just bellow those line, add the following:

if(strstr($hosts[$index],"://"))
    list($protocol,$hostPort) = explode("://",$hosts[$index]) ;
if(strstr($hostPort, ":"))
    list($host, $port) = explode(":", $hostPort);

Then, on EMail Settings inside Clientexec, use:

User: your-address@your-google-apps-domain

Password: your-google-apps-password

Host: ssl://smtp.gmail.com

Port: 465

Now, Clientexec should be sending mails without problems through your Google Apps email account, and all sent emails will be stored on that account.

Tags: , , , ,

Tags: , , ,

Durante la migración de la web de DeChalaca desde el servicio Grid-Service de MediaTemple hacia un nuevo VPS, el último punto que quedó por resolver fue que las fechas en la web se mostraban en inglés (aunque el Joomla estaba configurado para que lo hagan en español). El problema era que el servidor, un flamante Ubuntu 8.04, no tenía instalado las locales del español. La solución fue muy sencilla (como root):

$ cd /usr/share/locales
$ ./install-language-pack es_ES
$ ./install-language-pack es_PE

Para ver la lista de locales que están instalados en el sistema, se utiliza el siguiente comando:

$ locale -a

Tags: , ,

Existen algunas formas de hacerlo, acá les dejo un par.

Primera forma:

//list es del tipo IList
ArrayList arr = new ArrayList(list);
Item[] items = (Item[])arr.ToArray(typeof(Item));

Otra forma:

Item[] items = new Item[list.Count];
list.CopyTo(items, 0);

Tags: , , ,

Para determinar cuál es la versión exacta de un servidor SQL Server (ya sea 2000, 2005 ó 2008), basta con ejecutar la siguiente consulta:

SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')

En mi caso, la consulta me devuelve algo como esto:

9.00.3080.00 SP2 Developer Edition

Para versiones anteriores de SQL Server, podemos utilizar esta otra consulta:

SELECT @@VERSION

Vía: Microsoft Support

Tags: , , ,

Luego de haber instalado Windows 7 hace algunos meses, en un equipo donde tenía tanto el Windows XP como Ubuntu 9.04, quedó inaccesible este último. Esto debido a que el instalador de Windows no reconoce otro sistema operativo que no sea propio de Microsoft (a diferencia de Linux).

Se debe tomar en cuenta NO utilizar el Live CD de Ubuntu 9.10 para restaurar el Grub de las versiones anteriores de Ubuntu. Esto debido a que Ubuntu 9.10 y posteriores utilizan Grub2, que difiere mucho de la primera versión.

Lo primero que se debe hacer es iniciar la máquina con algún Live CD de Linux (como el de Ubuntu, que es el que utilicé en el proceso).

Una vez que está funcionando, abrimos un terminal. Vamos a necesitar los privilegios del root, por lo que lo más práctico sería ir al shell respectivo:

sudo -i

Luego, creamos un punto de montaje para la partición de Ubuntu:

mkdir /mnt/linux

Después, montamos la partición:

mount /dev/sda2 /mnt/linux

Donde sda2 (sd porque es un disco SATA, a por ser el primer disco duro, y 2 por ser el número de la partición) es la partición donde se encuentra Ubuntu. Si no estamos seguros de cual es la partición, podemos usar el programa GParted (visual) o el comando:

fdisk -l

Una vez que está montada la partición, podemos corroborar que sea la partición listando los archivos en ella:

ls -la /mnt/linux
ls -la /mnt/linux/boot

Luego de que estamos seguros que es la partición correcta, pasamos a reinstalar el Grub mediante el siguiente comando:

grub-install --root-directory=/mnt/linux /dev/sda

En caso aparezca algún error o advertencia, podemos probar el siguiente comando:

grub-install --root-directory=/mnt/linux /dev/sda --recheck

Donde sda hace referencia al disco (usualmente el primario) cuyo MBR será utilizado para instalar el Grub (ojo que NO incluye el número de partición).

Reiniciamos y deberíamos ver ya el menú de booteo del Grub.

Vía: Ubuntu Documentation

Tags: , , , ,

En una aplicación en la que estoy trabajando, surgió la necesidad de actualizar muchos registros de la base de datos, específicamente, lo que necesitaba era quitar un texto común dentro de un mismo campo para muchos registros.

Para ser más explícito, tenía algo como esto dentro de una tabla en la base de datos:

id filepath
1 files/archivo1
2 files/archivo2
3 files/archivo3
4 archivo4

Y necesitaba quitar el texto files/ de los registros que lo tuvieran. La magia nos la dará entonces la función REPLACE dentro de una sentencia UPDATE de SQL:

UPDATE {tabla}
SET {campo} = REPLACE({campo}, '{texto original}', '{texto de reemplazo}')
WHERE {campo} LIKE '{texto original}%'

En mi caso, la sentencia sería como sigue:

UPDATE files
SET filepath = REPLACE(filepath, 'files/', '')
WHERE filepath LIKE 'files/%'

Esto hace que primero se filtren los registros cuyo campo filepath comienza por la cadena files/ (nótese el signo de porcentaje solo al final), y luego se reemplace dicho campo por el resultado de la función REPLACE. Esta función toma el valor del campo, busca ahí la cadena files/ y la reemplaza por una cadena vacía (consiguiendo el efecto deseado).

La sentencia WHERE no es completamente necesaria, solo me aseguro que afecte a los registros donde el campo filepath comienza con ese texto y no a los que tengan el texto en otra posición.

Tags: , ,

FatCow nos ofrece un paquete con 1000 íconos web llamado Farm-Fresh para utilizar en nuestras aplicaciones y sitios web. Podemos descargarlo gratuitamente ya que tiene la licencia Creative Commons Attribution 3.0 License, lo que significa que podemos usarlos para cualquier propósito (open source, privado o comercial) con solo mencionarlo en los créditos.

Farm-Fresh Web Icons

Puedes bajarlos desde acá.

Vía Blog and Web.

Tags: ,