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

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:

sudo apt install openssh-client

In order to access the server via SSH, the server should have SSH Server installed and the service running in it. This will be pre-installed on almost all Linux servers.

Let's connect to the server now.

You need the following items to login to the server:

  1. IP Address of the server machine
  2. Username of the server
  3. The password of the user
ssh user@<ipaddress>

Here's an example command:

ssh ubuntu@45.244.96.73

The above command will ask for the password. If you enter the password, it will log in to the server.

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (1)Sample output of connect with Linux Server using SSH Command.

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:

sshpass -p <password> ssh user@<ipadrress>

And here's a quick example:

sshpass -p password ssh [email protected]

This is not the recommended way. Command line arguments are visible to all users (for example, ps -ef | grep sshpass). sshpass attempts to hide the argument, but there is still a window during which all users can see your password passed by argument.

There's also a command in Linux called history which displays your past commands. Any user who gain access to your machine may run the history command and find your server login credentials. But if you've entered the password in a prompt, it'll not be shown to users in the history command.

Here's the output of history command:

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (2)history command displays past commands

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:

  1. ssh
  2. login

How to log in with SSH

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

ssh <user>@<ipaddress>ssh [email protected]

How to log in with the login command

You can use the login command to switch the user inside the server.

Let's assume you've logged into the ubuntu user in the 45.244.96.73 server. Later you found that you want to switch to the ak user to perform some admin operations. In such a case, you can quickly switch the user using the login command.

Syntax for the login command is:

sudo login <username>

And here's an example to switch to the root user:

sudo login ak

The above command will prompt for the password similar to login via SSH.

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (3)Sample output to connect with Local User

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.

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:

mesg

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (4)Terminal command to verify if message access is enabled

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.

mesg y # Enable message accessmesg n # Disable message access

Let's try to communicate with others.

There are two commands available to communicate:

  1. write
  2. wall

The write and the wall commands use a fairly simple mechanism. Both commands take a message from one session and deliver it to other session(s).

How to use the write command

You can use the write command to message a single user (Direct Message).

write <username>
write ak

After entering this command, it prompts for the input message to send. We can send any number of messages using the write command.

Here's an example showing the communication between the users ak and gogosoon:

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (5)Sample output of sending message to the user

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (6)Sample output of received message using write command

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

mesg n

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (7)Turn off messaging for ak user

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (8)Trying to send a message to ak user from gogosoon user

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.

wall <message>

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (9)Sample command to send message to all logged in user

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (10)Sample output of received message from user gogosoon

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:

scp [OPTIONS] <user>@<src_host>:<file_src_path> <user>@<dest_host>:<file_dest_path>

Using the SCP Command we can do the following operations,

  1. Copy the file from our machine to the server machine
  2. Copy the file from the server machine to our machine
  3. Copy the file from one server to another server

Let's look at each of these operations in more detail now.

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

When copying files from the local to the server machine, you should enable SSH in the server. This is because SCP uses SSH to establish the connection between the client and server machines.

scp <filepath> user@hostname:<filepath>
scp sample.txt [email protected]:/home/ak/

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (11)Sample Output to transfer files from Local machine to Server

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (12)File uploading status

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (13)Sample.txt has been transferred to server

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:

scp server_username@<server_host>:<filepath> <local_path>

This command will copy the file server_file.txt from the server machine to the local machine in the test directory.

scp [email protected]:/home/ak/server_file.txt /home/gogosoon/test

If you leave the local_path empty, the file will be copied to the home directory.

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (14)Create file in server to transfer

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (15)Sample output of transfer file from server to local

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 <src_user>@<src_host>:<src_path> <dest_user>@<dest_host>.com:/<dest_path>
scp [email protected]:/home/ak/script.sh [email protected]:/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.

Linux Server Tutorial – How to Login, Communicate, and Transfer Files (2024)
Top Articles
Do House Cleaners Change Sheets? - Explained by cleaners
Business Analyst Salaries in India: 2024 Edition
Friskies Tender And Crunchy Recall
Live Basketball Scores Flashscore
Coverage of the introduction of the Water (Special Measures) Bill
9192464227
Produzione mondiale di vino
Santa Clara Valley Medical Center Medical Records
Conduent Connect Feps Login
OSRS Dryness Calculator - GEGCalculators
Pittsburgh Ultra Advanced Stain And Sealant Color Chart
Spartanburg County Detention Facility - Annex I
Playgirl Magazine Cover Template Free
Curtains - Cheap Ready Made Curtains - Deconovo UK
Xxn Abbreviation List 2023
Sport-News heute – Schweiz & International | aktuell im Ticker
25Cc To Tbsp
Voy Boards Miss America
Pekin Soccer Tournament
Officialmilarosee
CDL Rostermania 2023-2024 | News, Rumors & Every Confirmed Roster
Dover Nh Power Outage
Puss In Boots: The Last Wish Showtimes Near Cinépolis Vista
Heart Ring Worth Aj
Raz-Plus Literacy Essentials for PreK-6
Nesb Routing Number
Essence Healthcare Otc 2023 Catalog
Relaxed Sneak Animations
Stockton (California) – Travel guide at Wikivoyage
Mumu Player Pokemon Go
Kokomo Mugshots Busted
Everstart Jump Starter Manual Pdf
Puerto Rico Pictures and Facts
Craigslist In Myrtle Beach
Goodwill Thrift Store & Donation Center Marietta Photos
Pensacola 311 Citizen Support | City of Pensacola, Florida Official Website
Labyrinth enchantment | PoE Wiki
Trivago Myrtle Beach Hotels
What Does Code 898 Mean On Irs Transcript
Thelemagick Library - The New Comment to Liber AL vel Legis
Wayne State Academica Login
VDJdb in 2019: database extension, new analysis infrastructure and a T-cell receptor motif compendium
Powerspec G512
2Nd Corinthians 5 Nlt
The Many Faces of the Craigslist Killer
A rough Sunday for some of the NFL's best teams in 2023 led to the three biggest upsets: Analysis
Kaamel Hasaun Wikipedia
Aurora Southeast Recreation Center And Fieldhouse Reviews
300 Fort Monroe Industrial Parkway Monroeville Oh
Strange World Showtimes Near Century Federal Way
Southwind Village, Southend Village, Southwood Village, Supervision Of Alcohol Sales In Church And Village Halls
Craigs List Sarasota
Latest Posts
Article information

Author: Rev. Leonie Wyman

Last Updated:

Views: 6411

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Rev. Leonie Wyman

Birthday: 1993-07-01

Address: Suite 763 6272 Lang Bypass, New Xochitlport, VT 72704-3308

Phone: +22014484519944

Job: Banking Officer

Hobby: Sailing, Gaming, Basketball, Calligraphy, Mycology, Astronomy, Juggling

Introduction: My name is Rev. Leonie Wyman, I am a colorful, tasty, splendid, fair, witty, gorgeous, splendid person who loves writing and wants to share my knowledge and understanding with you.