Guide for SSH access and basic commands with Linux servers

This is a list of Linux commands that I have been using regularly, for SSH access to a web server and for small administration tasks.

I am not a system administrator, far from it… however, on a day-to-day basis, every week I have to enter various servers and carry out different types of operations for their management. I usually just do simple tasks and ask real sysadmins to do their job on server setup and security.

However, it is very important to know the most basic commands to be able to access a server and deploy applications, or be aware of the progress of various services, restart them, etc. Having said this, I clarify that the commands that we are going to see are simple and useful for the most basic tasks that a developer can perform.

It should also be noted that I usually use servers with Debian or Ubuntu, which is a derived distribution and therefore is very similar.

Access to a server by SSH

We’ll start by looking at SSH access to a server, a command that connects you to the remote server and allows you to work with it from the command line.

The command is “ssh” and follows from the IP address, or domain, of the server you want to access.

ssh domain.example.com

What happens with this dry command is that it connects you with the username you have on your local machine, so you usually need to give it a specific username:

ssh root@0.0.0.1

The user can be “root” or any other.

Once inside the server you can escalate your user to root with:

sudo su

Many commands like the ones we will see below for server maintenance require you to be logged in with “root” permissions.

See also  Custom Shapes in Photoshop

server maintenance

Now we are going to see some essential commands to keep the server up to date.

If you manage or use a server, one of the most important things you should do is keep it up to date. Many of the updates that are published in the free software on your server (either the operating system itself or the programs you have installed) are often security updates, so it is important to install them all.

When you log into the server it usually informs you about the available updates, and how many of them are related to security:

update programs

On Ubuntu or Debian the “apt-get” command is used to install the updates. You usually do the following first:

apt get update

With that you get to update the repositories, so your server really knows what has to be downloaded again. Then you run the command:

apt-get upgrade

This second command is used to install the updates available for your system, both the operating system itself and the programs that you have installed through the repositories.

Note: apt-get works for Debian-based distributions (Ubuntu, Mint, Debian itself…) other distros like CentOS use the “yum” command. I guess there will be more package managers but I haven’t used them.

Sometimes, despite doing an apt-upgrade, some packages remain uninstalled. So you use:

sudo apt-get dist-upgrade

Install new programs via repositories

In Linux it is important to install the programs via the repositories of the system itself, this ensures that you find out when there are updates, and these can be installed easily.

See also  /articulos/2132.php

It is normal that when you enter a server for the first time you do not have some basic commands that you usually use, such as the one that launches the Vim editor, or Nano, Git, etc. In that case you should simply install these programs using the repositories, with the same apt-get (or whatever package manager is used on your system).

For example, installing vim is accomplished with:

apt get vim

Shutdowns or reboots

Sometimes you need to reboot the machine, or shut it down. It’s also easy via ssh.

Reboot the machine. Shut down and start the machine again. Important because some updates require a server restart.

reboot

Be careful with the shutdown command, which can turn off the server and not start it again. You may have to enter the manager of your server, on the website of the provider where you manage it, to start it again

shutdown -h now

This is another alternative to rebooting the machine. Like a reboot.

shutdown -r now

When the machine reboots it will usually drop out of your ssh connection and you will have to reconnect after a minute or two, using the ssh command again.

Maintenance of usual services

Many of the times that a problem occurs on the server is solved by restarting the services, be it Apache, MySQL, Nginx. Obviously if something more serious is going on this won’t save you, but luckily a restart of the services is enough.

nginx service

If you use Nginx you can restart the service with:

systemctl restart nginx

See also  Install new shapes in Photoshop

Note: Remember to use “sudo systemctl start nginx” or make sure you are root or have escalated to superuser. Likewise, to reboot you could also do a stop command first and then a start command.

To view server status:

systemctl status nginx

If that doesn’t work for you, alternatively try:

service nginx restart

apache service

If you use Apache, then you can restart the service with this command: (remember to use sudo or be superuser).

/etc/init.d/apache2 restart

Another alternative that could help you is:

service apache2 restart

In the same way, you can do a “stop” first and then a “start”, which would be the equivalent of a “restart”.

mysql service

Another of the services that can get stuck and make your website work suddenly very slow is MySQL. In these cases, a restart is also usually “hand of saint”.

/etc/init.d/mysqld restart

Alternatively:

service mysqld start

Updated: On some servers I have noticed that the MySQL service is called “mysql” and not “mysqld”. If it happens in your case, you may receive a message like “mysqld: unrecognized service”. In that case, the command in question would be:

service mysql start

conclusion

With this we finish with the basic list of commands for access to a server and its maintenance, for the simplest actions that you may need. We will make other collections of commands in the future that we are sure you will also find very useful. You can check everything in the .

Loading Facebook Comments ...
Loading Disqus Comments ...