Connect to server command line linux

Connecting to a Remote Server Over SSH on Linux

Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.

A secure shell (SSH) is used for secure communication between devices. When most people refer to SSH, it is within the context of connecting from a local computer to a remote server, commonly for administration tasks related to website hosting.

This article covers the basics of connecting to a remote server (such as a Linode) over SSH on a Linux system.

Before You Begin

  1. Ensure you have a Linux server with an SSH server (like OpenSSH) installed. Most Linux distributions have an SSH server preinstalled. If you wish to deploy a new server, follow the Creating a Compute Instance guide to create a Linode.
  2. Your local computer needs an SSH client that can be used through a terminal application. Most modern Linux distributions have SSH installed and ready to use.

Open the Terminal

On your local computer, open the terminal application you wish to use. The terminal allows you to access your operating system’s shell environment and run programs through the command line.

If you’re using Linux through the command line, you are already in the terminal and can skip this section. If you are using Linux through a desktop environment (a graphical interface), you’ll need to locate and open the terminal application that comes with your Linux distribution and desktop environment. In most cases, pressing Ctrl + Alt + T on your keyboard opens the default terminal.

  • Gnome: The default terminal emulator is Gnome Terminal. Gnome is the default desktop environment for Ubuntu.
  • KDE: The default terminal emulator is Konsole. KDE is the default desktop environment for Manjaro.

If this key combination does not work for you, other instructions for opening a terminal vary depending on the Linux distribution and desktop environment you are running. In many cases, you’ll want to open the application search tool and search for “terminal”.

Connecting to the Remote Server Over SSH

  1. Within the terminal, enter the following command, replacing [username] with the username of the remote user and [ip-address] with the IP address or domain name of the remote server.

If the server’s SSH port is something other than 22, it needs to be specified in the SSH command. To do this, use the -p option as shown in the command below. Replace [port-number] with the port number that the remote SSH server is using.

The authenticity of host ‘example.com (93.184.216.34)’ can't be established. ECDSA key fingerprint is SHA256:d029f87e3d80f8fd9b1be67c7426b4cc1ff47b4a9d0a84. Are you sure you want to continue connecting (yes/no)?

You can verify the fingerprint by following the instructions on the Verifying the Authenticity of a Remote Server guide.

Читайте также:  Ipad mini установить linux

If you recently rebuilt your server, you might receive an error message when you try to connect. This happens when the remote host key changes. To fix this, revoke the key for that IP address.

Warning: Permanently added 'example' (ECDSA) to the list of known hosts.

Once you have successfully connected, your terminal should be using the remote shell environment for the server. Your command prompt should now show the username and hostname configured for the server. You can now run any commands that you have available on that server. This includes many of the basic Linux commands, such as ls , cd , rm , and those covered in Using the Terminal guide. Getting to know these commands will help you navigate around your server.

Ending the SSH Session

After you are done, log out of the session by typing exit . The terminal then shows something similar to:

logout Connection to 93.184.216.34 closed.

At this point, the shell prompt returns to the one for the local workstation and the terminal application can be closed if it’s no longer needed.

Sending Commands Over SSH

Instead of using SSH to open your remote server’s console, you can run commands on your server without leaving your local shell environment. This can enable you to quickly run commands both locally and remotely in the same terminal window.

Sending a Single Command

To run a single command on your remote server, use the following command. Replace [username] with the username of the remote user, [ip-address] with the IP address or domain name of the remote server, and [command] with the command you wish to run.

As an example, running ssh me@192.0.2.0 ls lists all the files in the home directory of the user called me . This can be useful to find the uptime of the server ( ssh me@192.0.2.0 uptime ) or maybe determine its Linux distribution and version ( ssh me@192.0.2.0 lsb_release -a ).

Sending Multiple Commands

To run multiple commands on your remote server (one after the other), use the following command. Replace [command-1], [command-2], and [command-3] with the commands you wish to run.

The commands should be separated by a semi-colon ( ; ) and all of the commands together should be surrounded by double quotation marks ( » ). For example, if you wanted to create a file named bar.txt in a directory called foo within the user me’s home directory, run: ssh me@192.0.2.0 «mkdir foo; cd foo; touch bar.txt .

Using sudo

It’s recommended to disable root access over SSH and only log in to your remote server through a limited user account. However, some commands require elevated privileges, which can usually be accomplished by prepending the command with sudo . If you attempt to do this while running commands directly through the SSH command, you may receive an error such as “no tty present” or there isn’t a “stable CLI interface”. To run the sudo command in these instances, use the -t option, which forces a psuedo-terminal allocation. For example, to update your packages on a Debian-based system, run ssh linode@example.com -t «sudo apt update» .

Читайте также:  Astra linux системные значки

Going Further

Troubleshooting SSH Connection Issues

If SSH isn’t connecting you to your Linode, you may need to investigate the state of your server. See the guide Troubleshooting SSH for assistance.

Increasing Security

  • Now that you can connect from your Linux machine to the Linode over SSH, save not only time but also make the connection even more secure by using SSH public key authentication. For more information, see SSH add keys.
  • See the “Harden SSH Access” section of Setting Up and Securing a Compute Instance guide to review how to secure SSH on the server’s side, and the Advanced SSH Server Security for more information on making it even more secure.

This page was originally published on Friday, June 25, 2021.

Источник

Linux Server Tutorial – How to Login, Communicate, and Transfer Files

Arunachalam B

Arunachalam B

Linux Server Tutorial – How to Login, Communicate, and Transfer Files

Did you know that 96% of the top 1 million web servers are running Linux?

Yes. You heard that right. So being able to work with Linux servers is a great skill to have.

In this article, you’ll learn how to connect to a Linux server using SSH, how to communicate with other users on the server, and you’ll see a handy file transfer mechanism.

A quick note before we dive in: the IP address that I’ve given in the example commands and the one in the example screenshots will vary. The reason is, I don’t have a server to demonstrate everything, so I made my laptop a server. So, all my example screenshots will be displaying my local IP addresses beginning with 192.168. .

How to Log in to a Server Running Linux

I love to develop software, but I really dislike DevOps and deployments. When I have some kind of DevOps work, I’ll hand it over to the specialist in my team and stay away.

The reason is my lack of experience in handling servers. But sometimes, when my team members are not available, I’m forced to do deployments.

So, the initial step for a (manual) deployment is to log in to the server. To log in, you need to know the IP address and the password of the server.

Above all, you need to have the SSH client installed on your machine. This comes pre-installed on almost all Linux distros.

If you don’t have it installed, you can install it by running the below command in the terminal:

HgByhOjGdN5KCqnk-0RXRAqvrHXdttXbpxjatpEOm6f7k7_1VAEUZKu7xVZ6CrLqpeG6vAu2Lj3zj7sSFpUPF-7TEFRJ3FIeMOXAQyMyPXK2DWYSf2zPRM9onI1U-ieT9zRNee8blRaysH4LgE3ctFc

Alternatively, you can log in without any prompt by adding the -p option with the sshpass command prepended to ssh command. You need to have sshpass installed to try this method.

The syntax looks like this:

image-265

How to Log in to a Particular User in the Linux Terminal

In Linux, we can log in to different users using two different approaches:

How to log in with SSH

As already discussed with the SSH command, we can login to another user using the same syntax.

NdnozHMxq8yjUemRfgXbLseAJJOtdjFuogF80P3sXiHA9WsH-kaM7pfsqq7u9tMrCgB1kIU8up5_stEPbov2w7SEI8Tx-0jWfSDwGn4xMX0U0CZr_cG3GymiYQTQ3FIZNLGCRZDLzOwvyrvy1cWGq9I

Hurray, we successfully logged in to another user. Now let’s explore how to communicate with these sessions.

A quick note before jumping onto the communication section. If you wish to log out of the logged-in user, you can simply run the logout command.

How to Communicate Between Sessions in Linux

Did you know that you can use your Linux terminal as a chat interface?

Well, yes – you can. If you and your colleagues are connected as their own users to the same server using SSH, then you all can communicate via the terminal.

Читайте также:  Sudo командная строка линукс

As with all such features, there are a few pre-requisites to continue.

First, make sure that message access is enabled in the receiver system. To verify that, type the following command in the terminal:

GhfC5V8FTtbZMrFpMef_tdVanRwDZv7qksWLAtSp2Oi6LixFWOLUme82szxja60ho6h04jHi5cUjkFTAgKepTKw3KsRjr7Yx1yt1bJ_rvCWr1CFDqX9L-rfASEuSHWD4Emx7BdBKAyLqGcl3omuRsYg

The response will be either yes or no.

is y – Message access enabled

is n – Message access disabled

To toggle this feature, you have to pass the symbol along with the mesg command.

j5imQ3k0CpoU80sgoesN-0-C2YE94Q130NeWqCaWx9jU42jEhKKR31Izy1H5k6WSb5TRd5pVUfa4CPg0GUeY_qnIzcoapWEK8D6W42JqMIVrFe7vlBqVWRvbmqcTvYIKvRw4nUUTG59zlZ_MRcP3s7oDXtSsy3TbbeHr8oX3bB8mSxPxkXy6zsVjJ9WwlI8HfXJJVi6RL8BgTHaSUivl1rZzVpD9aEq6LPn9Gfq8_8FHTzwXE2FGtUz4TTO46b5GU8NXYCu-8gY-l4k0V328Sj0CHe6OMuay7SxdGlkf5LTLdg

Let’s turn off messaging on the ak user and try to send a message from the gogosoon user.

Nyt9Ror-xWpTtnGd77lkjXM_cb7hUcj1fE3fbJEk-kEc-EPsUxQCwhpuo_br1ba44XEdnGa9WzDQkE2OcY4lZW9R7LFCob4kNVYBPmm65GNhpfK-UQ198i73dWynZ4pfeX4kzOB3oWwE0-HzLeNA9SsQY3yKIRAMJpxHOlaY3jJfyuQI5zLDyB8iecBIkAIzeuAHobYU1q6IiWDyN9sVu1Xikl5psyLMtpy7TFYAxohNbxINlQFS-5zE7Y18TSbYlVR6EhvCDWCBfWR3XYVL2CheGvny3CsTLCkiq3_f9F8hjY

How to use the wall command

You can use the wall command to write messages to all logged-in users. This command will display the message or the contents of a file to all the logged-in users. Basically, it will broadcast the message to all the sessions.

9emd9tiz1MkQHQDYaCs_2Y8Cc87T1Yt3GLKsYPGZ9IYEZGecDE95zaLZJdpNik5szyKB1_Y-d60WsOIlZPVGy1YrNWmfb2tbCQltO3e6fxxXX1npqGnmaVnuQvqOsaz18h3b8Q25GUpHnzVtaBiWQwIey4zUh9Rv_OEZcn3LUn4ksRg_eMekUUNyOvvny7_E0PGvbODYjkYGcZ7fsBoZ7W3DwZQOshbCJlhm7AQ6_ty5rCItysHSAU_ceGvLmuUFimchZe8DQRtx8R9MK_CDfmOz1an14Qd6ScB3YHcYVrMY5Q

Here we can see the message in the user ak . Similarly, it prompts the message to every logged-in user.

How to Transfer Files to/from the Server Using the Linux Terminal

I believe most people would recommend using FTP to transfer files from and to the server. FTP provides more control over the files such as the ability to rename, delete, move, and modify files from the remote computer.

But FTP does not offer protection against anyone who may be trying to view your network credentials.

We can do this using a Linux terminal – and believe me it’s super simple.

You can transfer files using the scp command.

SCP stands for Secure Copy Protocol. This command allow the user to share the files in a secure way. Unlike FTP, SCP is highly secure. It uses secure shell to encrypt both your data and credentials. SCP does not provide facilities to control files.

Since this command follows the end-to-end encryption protocol, it uses encryption over an SSH connection. This will protect the files from suspicious attacks.

Transferring files via SCP will be slow when compared with FTP. But, it’s a better alternative to FTP if you need a one-time movement of files.

The syntax for the SCP command looks like this:

xRevVCaYkcjReW_KL5z3AR4URLrtfj7ddjb5syy9XYAM77ndXOwPsq5aqGpEY3Y6Py3ro2kYaklDYOjqSkf4t_eFDwsTvlHn7-EyI8GW1UXKSMtb17kThqdrgDZTLpjIrr2Q9b82EJqJbADsm5IAmRYR1Seq1__aIY64McpCrOxq2EHDzIUbkH9Yp_hjaGdTBjMx_Ig1Dl4JImNmeUJ83rKQnXbgaMOeqkgNwG7NAFEF7uHFPFzsmmGcrxXeAKYEbZSptDmPY5DI-YN7shaLmESQNwan8rwaVXI--TffliTR-MQn41hy9eTLlH8qHHdBNDHDP-svOKwuyEJI_1xcpQd3dMBepILQA6hu_yEA-fj-Yaguq6hoqYOqR5GunCfmnsAosKGosovwjKdXAFuLODjUXV4GwtLPUDQy9a69oLP4pIUkcoKnj2doetcfDQUwBiNDg

The above screenshots show that the file was copied to the server.

How to copy the file from the server machine to the client machine

Let’s see how to transfer the file from the server to our local machine:

oDuUIGXLgFnUYwZY1qrym9lsy8rvLI-cktIOMA-0eVASMw3c1NofUApRERSH8jAEt8Jqv8KTML7xHT_oQihD6cECczYyeTI0MyVlrixpR0CJhl6oMbmWqGuvuyMa9yXV2esY0XovawvN47Y5xV9_iG48UQdbKsHlapYP3pIKrlYM5_qAdVGBxN5I_cr_u3ugIyiHuzTXjHSjWsGMKESFascLc8KvqH_aAglXfB2qSiW2-90t3ceWVOQ-PYs-tkym20dakTq7cilKHe0_CabuBr8ufueVqmam1CnfTEQKL7dSDo

How to copy the file from one server to another server

Let’s assume you’re taking a backup of a file from a server. You don’t want this file to be stored on your machine due to some security concerns. But, you want to transfer this file to another server.

Copying files from one server to another server is also possible with the scp command:

scp ak@45.244.96.73:/home/ak/script.sh gogosoon@45.244.196.173:/home/gogosoon/

Conclusion

Alright, we’ve come to the end of this tutorial. I hope you all enjoyed learning about these helpful commands.

If you are a DevOps Engineer, Linux Developer, or you’re learning Linux, these commands will be very useful. If you enjoyed this guide, please share it with your colleagues/friends who are more into working on servers.

To learn more about Linux, subscribe to my email newsletter on my site and follow me on social media.

Источник

Оцените статью
Adblock
detector