COMPUTER NETWORKS UNIT Communication takes place between processes

Remote Login port

Port / December 31, 2021

This tutorial is about SSH and SCP. You will learn how to connect to a remote host and how to copy between hosts. This tutorial also documents a few important differences between the commands.

Difficulty: Basic

Before we start: in this tutorial, you will come across both SSH and ssh. The difference is this: SSH is the general protocol, and ssh is the linux SSH client command.

SSH is some kind of an abbreviation of Secure SHell. It is a protocol that allows secure connections between computers. In this tutorial, we’ll be dealing with the ssh command on Linux, the OpenSSH version. Most Linux distributions feature the OpenSSH client today, but if you want to be sure, have a look at the SSH manpage on your system. You can do this by typing:

[pinehead@localhost ~]$ man ssh

Note: this should be done in a terminal. This tutorial assumes that you have some basic terminal knowledge, like knowing how to start a terminal session on your system and being familiar with the basic commands and syntaxes.

If it displays something like this

ssh – OpenSSH SSH client (remote login program)

In the most simple case, you can connect to a server that supports ssh with a syntax as short as this:

[pineehad@localhost ~]$ ssh yourserver

Note: If you do not have any ssh server nearby that you can access, you can also try this command with your own computer as a server. To do this, replace “yourserver” with “localhost”.

Of course, yourserver should be replaced by a hostname or an ip address of the server you want to connect to. As you can see in the terminal snippet, I am logged in as pineehad. If you do not specify a username (I’ll explain how to do that later in this tutorial), SSH will assume that you want to login with the username you’re currently logged in with. So, in this case, SSH will try the username pineehad.

Of course, you need to be sure that the server supports ssh connections. The ssh client tries to connect to port 22 defaultly. This means that, if you want to connect to a remote host with the default settings, you should make sure that, if applicable, port 22 is forwarded to the server you’re trying to connect to. You will find more regarding the SSH port further in this tutorial.

Now, back to the command we ran. If the server supports SSH connections and you can reach it by port 22, you should be prompted for a password (if this is the first time you try to connect to the server, ssh will first ask the question if you want to continue connecting, which can generally just be answered with a ‘yes’). If you type a password here, you won’t see asterisks appearing. Don’t panic, this is ssh’s normal behaviour. It makes connecting using ssh even more safe, because any accidental spectators won’t be able to see the length of the password. After entering the password, if the username and the password were correct, you should be running a shell on the server. If not, make sure you are connecting to a server of which you know that you should be able to login with your username and the specified password. You could try connecting to your own computer (see the note beneath the terminal quote) or read on to learn how to specify an other username.

Once you’re done trying the ssh shell, you can exit it by pressing Ctrl + D.

It’s actually quite simple to specify a different username. You might even already be familiar with it. See the following example:

[pinehead@localhost ~]$ ssh yourusername@yourserver

The above will make ssh try to connect with the username “yourusername” instead of (in my case) pineehad. This syntax is also used by a lot of other protocols, so it’ll always come in handy to know it. By the way, you will still be asked for a password. For security reasons, it is not even possible to directly specify the password in the syntax. You will always be asked interactively, unless you start configuring the server in an advanced way (which is exactly why that topic is out of this tutorials scope: this tutorial documents how to use the clients, not how to configure the server).

There are many reasons to move the ssh service to an other port. One of them is avoiding brute-force login attempts. Certain hackers try to get access to ssh servers by trying a lot of common usernames with common passwords (think of a user “john” with password “doe”). Although it is very unlikely that these hackers will ever get access to the system, there is an other aspect of the brute-force attacks that you’ll generally want to avoid: the system and connection load. The brute-force attacks usually are done with dozens or even thousands of tries a second, and this unnecessarily slows down the server and takes some bandwidth which could’ve been used a lot better. By changing the port to a non-default one, the scripts of the hackers will just be refused and most of the bandwidth will be saved.

As the ssh command can’t just guess the port, we will have to specify it if it’s not the default 22 one. You can do that this way:

[pineehad@localhost ~]$ ssh -p yourport yourusername@yourserver

Of course, you will have to replace “yourport” with the port number. These is an important difference between ssh and scp on this point. I’ll explain it further on.

Sometimes, especially in scripts, you’ll want to connect to the remote server, run a single command and then exit again. The ssh command has a nice feature for this. You can just specify the command after the options, username and hostname. Have a look at this:

[pineehad@localhost ~]$ ssh yourusername@yourserver updatedb

This will make the server update its searching database. Of course, this is a very simple command without arguments. What if you’d want to tell someone about the latest news you read on the web? You might think that the following will give him/her that message:

[pineehad@localhost ~]$ ssh yourusername@yourserver wall “Hey, I just found out something great! Have a look at!”

However, bash will give an error if you run this command:

bash: !”: event not found

What happened? Bash (the program behind your shell) tried to interpret the command you wanted to give ssh. This fails because there are exclamation marks in the command, which bash will interpret as special characters that should initiate a bash function. But we don’t want this, we just want bash to give the command to ssh! Well, there’s a very simple way to tell bash not to worry about the contents of the command but just pass it on to ssh already: wrapping it in single quotes. Have a look at this:

[pineehad@localhost ~]$ ssh yourusername@yourserver ‘wall “Hey, I just found out something great! Have a look at!”‘

The single quotes prevent bash from trying to interpret the command, so ssh receives it unmodified and can send it to the server as it should. Don’t forget that the single quotes should be around the whole command, not anywhere else.

The scp command allows you to copy files over ssh connections. This is pretty useful if you want to transport files between computers, for example to backup something. The scp command uses the ssh command and they are very much alike. However, there are some important differences.

cumberland university california baptist university upper iowa university north carolina state university michigan state university indiana state university grand canyon university student portal newman university prairie view a&m university rockhurst university buffalo university university of nebraska-lincoln lobos management university of texas at dallas fitchburg state university northcentral university difference between college and university eastern kentucky university niagara university caldwell university university hospital salem state university simon fraser university maryland university nc state university cabrini university full sail university calvin university loyola marymount university where is liberty university university of georgia university of california san diego gwynedd mercy university university of michigan basketball drury university university of nebraska-lincoln yale university capella university login university at buffalo where is duke university indiana university of pennsylvania liberty university football drake university university of the cumberlands medical university of south carolina fordam university saginaw valley state university savannah state university xavier university university of colorado boulder pacific university oklahoma city university william penn university vanderbilt university medical center walsh university university of california, davis university of florida football university of nebraska university of the people wastw management walsh university grand canyon university student portal niagara university waste management login cornerstone university real star property management american case management association lee university university blue jordan 1 indiana university football westfield state university aspen university chapman university neumann university university of oxford murray state university dominican university graceland university university of tulsa university of oregon football university of missouri lodi property management university of south alabama dillard university indiana university basketball university blue jordan 4 stratford university university of texas stetson university ems management avila university loyola university university park mall james madison university friendship university university of washington five star property management western carolina university university of utah seton hall university mount saint mary's university st joseph university george washington university mcneese state university columbia university acceptance rate trinity university university of alaska radford university lincoln memorial university oakwood university viterbo university tennessee state university akron university university of evansville delaware valley university madonna university southern virginia university langston university toledo state university cambridge university