Linux Server Access
Contents
Introduction
This page describe methods for accessing and using a remote Linux server. We'll be using the example of digdug.cs.endicott.edu. However, the instructions will work for any Linux server (just change the name).
SSHing into a Linux box
Many of our classes use a Linux box named digdug. It has a few databases (both relational and NoSQL) as well as web server tools. In order to use it, you'll have to make a secure connection using SSH. The instructions below will guide you through that process step-by-step.
Step 1: Acquire access to a terminal
In order to log into the remote server, you'll need some way to ssh (an acronym for "secure shell"—a way to establish a secure remote connection to another machine). If you run Mac or Linux, that's easy—just use the Terminal app. In Windows, you should use ConEmu; see Installing ConEmu for details.
Step 2: SSH to remote machine
Now we need to ssh to the server. SSH stands for "secure shell"; it is used to create a secure connection between a client (e.g., your laptop) and a remote machine (e.g., our class server). Open your console and type the following
ssh -p 1915 [your server username]@digdug.cs.endicott.edu
where [your server username]
is the server
username I emailed you. Once the connection has been made, you'll be asked to
enter your password. Enter the server password I gave you.
Step 3: Welcome to digdug!
Now you are logged in—nice job! If this is your first time logging in, you should change your password. You can do that by typing:
passwd
You'll be prompted to enter your server password—do that and hit "Enter" when you're finished. Next, you'll be asked to enter your new password. You won't see anything appear as you type, so you'll have to keep track of it in your head. Press "Enter" once you've finished. To make sure you've done it correctly, you'll be asked to re-enter your password. Go ahead and do that, hit "Enter", and the program will let you know if there were any problems. Remember this password—you'll need it the next time you go to log in.
(Back to top)Copying files to and from a remote Linux server
There is a tool called SCP (Secure CoPy) which uses SSH to copy files between two computers. The format of the command is one of:
Copy a file named [local file] from the local machine to a remote server named [server] via port [port]:
scp -P [port] [local file] [user]@[server]:[remote file/dir]
Copy a file named [remote file] from a remote server named [server] via [port] to the local file system:
scp -P [port] [user]@[server]:[remote file] [local file/dir]
Note that in the first case, the location we're copying to can be a directory or a file—if the former, then the file being copied will retain its original name; if the latter, it will get the new name. Similarly, in the second example, the local location can be a directory or file, causing the copied file to retain the same name (former) or get a new name (latter).
Here are a few examples. Lets say I have a file named foo.txt, and I want to copy it to digdug to my home directory:
scp -P 1915 foo.txt hank@digdug.cs.endicott.edu:.
Note that what goes after the ':' is the path to where to put the file. This is relative to your home directory on the remote server. The . means the present directory, i.e., my home directory (/home/hank).
Now suppose I want to copy the file public_html/index.html from digdug to my local machine in the current directory. I'd do:
scp -P 1915 hank@digdug.cs.endicott.edu:public_html/index.html .
Copying multiple files
You can copy multiple files or whole directories. However, a more network-
friendly way to copy multiple files and/or directories is to first combine and
compress them, copy that file over, and then uncompress it. You're probably use
to zip files. There's a more Unix-focused alternative to zip files, which
involves doing two things: creating a tar (Tape ARchive) file (this concatenates
all files/directories together, but does not compress them) and then compressing
it with gzip (GNU Zip). Luckily, we can do both steps at once using a flag to
the tar
:
tar -czf myTarGzipFile.tar.gz [directory or file list]
This takes all of the directory or files listed and creates a gzipped tar
file named myTarGzipFile.tar.gz. The extension tar.gz is
conventional, though sometimes it is abbreviated to tgz.
The flags -czf
stand for "create zipped file".
To unpack a tar.gz file, do this:
tar -xzf myTarGzipFile.tar.gz
The flags -xzf
stand for "extract zipped file". This will
unpack the given tar.gz file in the current directory.
Editing files on a remote Linux server
There are many ways to edit files on a remote server. I'll cover a few here.
Method 1: SCP
The simplest, though most annoying, method of editing a remote file is to
edit it locally, and then use the scp
command to copy the changes
over to the remote server.
Method 2: Git
If you're using Git, you can use that to sync between machines. This, however, requires that wherever you edit a file, you commit changes to your Git repository, push, and then on your remote server, pull. The plus side is that only changes are transferred over the network, not every file.
Method 3: Command line editors
The best option is to become familiar with a command line editor. There are many to choose from. My favorite is Vim, but here's a list of popular ones along with links to pages that discuss them more:
(Back to top)Basic Unix commands
This section of the Command Line Interface page is dedicated to basic Unix commands. It covers things like listing the files/directory in the current directory, changing directories, etc.
(Back to top)