2.4.8. Network connections#
Up until now, you have been using the shell to interact with your own computer. However, as we discussed before, Unix originated in a networked environment. Traditionally, Unix networks consisted of a small number of very powerful servers and a number of not-so-powerful workstations. In fact, in the very first Unix networks there usually was just one server[1]. Users connected to that server using dumb terminals, which were little more than a keyboard and a text-based screen. However, as computer power increased and got cheaper, it became feasible to buy computers which could do much more and place one on each userās desk. In fact, in some networks the workstations are now more powerful than the servers. Nowadays, Unix servers are integrated in your wireless router and media player, and more importantly: your robot!
2.4.8.1. Logging in onto a remote computer#
Provided you have the necessary permissions, you can log on to any other Unix system over the network. Nowadays, the network connections are made over the internet, using the TCP/IP protocol. Every computer has a unique IP address that identifies it. Originally, you would start a remote terminal session using the telnet
command, but as telnet
copies everything you type and see transparently over the network (even your password), it is not very secure.
In contrast, ssh
encrypts both the password and data, and also verifies that youāre talking to the right computer. Of course, if youāve never connected to the computer before, itās hard to know whether itās the right one. The correct way is to ask the administrator for the hostās fingerprint and check that it matches the one you see[2].
Exercise 2.43
You have an account on the TU Delft Linux server the Student Linux Bastion Host.
Use the ssh
program to connect to it, with hostname student-linux.tudelft.nl
, and
your netid username and password as the credentials (replace [NETID]
and [NETID_PASSWORD]
below):
$ ssh [NETID]@student-linux.tudelft.nl
The authenticity of host 'student-linux.tudelft.nl (131.180.123.205)'
can't be established.
RSA key fingerprint is 2c:b1:8c:90:45:5c:62:56:9b:a3:2a:55:60:e4:5a:03.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'student-linux.tudelft.nl, 131.180.123.205'
(RSA) to the list of known hosts.
wcaarls@student-linux.tudelft.nl's password: [NETID_PASSWORD]
Last login: Fri Apr 16 09:17:34 from somehost.somewhere
-bash-4.1$
Note you will have to type yes
and press ENTER when asked if you are sure you want to connect.
As you can see, you get a shell prompt just as if you were working on your own computer, though slightly more spartan.
2.4.8.2. Finding logged in users#
You can use all the commands that you have learned on remote computers as well. Additionally, you can see what other people who are logged on to the same computer are doing. To find out who is currently around, you can use the command
$ who
It shows you who is logged in, on which terminal (pts
, from pseudo-terminal slave), and since when. For example:
wcaarls pts/0 2010-07-28 14:06 (x031153.tudelft.net)
gavanderhoorn pts/10 2010-07-28 14:32 (x031153.tudelft.net)
...
You can learn quite a lot from this. For example, thereās an administrator currently logged in, wcaarls
, half an hour before we did. The administrator has the power to read and even remove all your files, so itās best not to write bad things about him or get into a fight[3].
Exercise 2.44
Try the who
command. Also try the w
command. What are the differences? What do you think the IDLE
field in the output of w
means?
If you ever get confused as to who you are yourself, you can try the command
$ whoami
Exercise 2.45
What does whoami
tell you?
2.4.8.3. Finding logged in users#
Finally, thereās a command to get detailed information on a specific user: finger
.
Exercise 2.46
Use the finger command to find out about yourself:
$ finger username
in which, of course, you should replace username
by your own login name.
Note that this gives quite a bit of information, among which your shell and what your plan is. Plans were used to tell people about what youāre doing at the moment. With blogs, facebook and twitter, no one uses them anymore.
2.4.8.4. Writing and talking#
There are a number of Unix commands which allow you to interact with other users. However, as youāre probably the only user logged in at the moment, we will have to ``fakeāā another user. You can do this by logging in again using a different terminal emulator.
Exercise 2.47
Open a second virtual terminal and log in to rsplinux
again. Use who
to find out how many users there are at the moment. Remember the name of the second terminal (for example, pts/1
).
The simplest command is write
. This sends messages to other users.
Exercise 2.48
Return to your first virtual terminal and type:
$ write rsplx001 pts/1
replacing, of course, rsplx001 by your login name and pts/1
by the name of your second terminal. The system will now ask for input; just type a message and press
Enter. If you want to stop entering lines, press Ctrl-D.
Now look at the second terminal and see whether your message has arrived. Note how it prints your name and terminal, so this feature sadly canāt be used to send fake messagesā¦
Note that writing is a bit intrusive, as the message will be printed on the other userās screen without warning and will overwrite anything thatās there. Fortunately, thereās no risk that the text you enter will actually be used as input for a program, but still it can be annoying. If you want to avoid being written to, you can enter:
$ mesg n
so that users trying to write to you will see the message
write: rsplx001 has messages disabled on pts/1
Exercise 2.49
Try disabling messages on your second virtual terminal, and writing to it from the first virtual terminal again.
You can enable messaging again by entering mesg y
.
Writing can be useful when you want to send quick one-liners such as
There's cake at the 10.30 coffee break
or
Get out of there, the building's on fire!
but less useful for having conversations. To really talk to another user, use the talk
command, with the same arguments as write
. The user you want to talk to will receive a message saying that thereās someone who wants to talk to him. He will then have to respond by running talk
himself. Next, you will see a split screen in which you can type in the top half, and the other user can type in the bottom half. As you can imagine, talk
usage has somewhat declined since the advent of ICQ, MSN and other instance messenger programs.
Exercise 2.50
Open a talk session between your first and second virtual terminal.
Once youāre tired of talking to yourself, log out of the second virtual terminal using the exit
command or Ctrl-D shortcut, and return to the first.
Exercise 2.51
If someone else is logged on to your system, try to talk to him/her.