Unix Access & C++ Compilation

Unix Servers and Accounts for CS Students

Unix Servers
Server Description
thecity.sfsu.edu Department of Computer Science Server
libra.sfsu.edu University Server
Getting Unix Server Accounts
Server Instructions
thecity.sfsu.edu You should already have an account if taking CS courses. If not request an account by contacting the department office. Your Username is the first part of your SFSU email address (WITHOUT the @sfsu.edu) and the Password is your Student ID. You use the same information to access the lab machines in SCI 254.
libra.sfsu.edu Request an account from Account Services, Division of Information Technology. Click here. The Username (first part of SFSU email address - WITHOUT the @sfsu.edu) and Password are the same as when accessing your SFSU email account.

Remote Access to Unix Servers

There are many programs you can use to login to remote machines and to transfer files to and from remote machines (from either end). Here is a brief summary (a very short description for each program)

Common Remote Access Tools
Tool Description
telnet a program which is used for logging into a a remote machine
ftp a program which transfers files to and from a remote machine
ssh & sftp
ssh & sftp work the same way as telnet & ftp. They are recommended 
over conventional telnet and ftp because they encrypt and transfer 
data securely whereas telnet and ftp pass everything in PLAIN TEXT, 
including passwords.

Students are encouraged to use ssh and sftp. This document provides information for ssh and sftp only.

Connecting to a remote Unix server from Windows

If your local machine is a Window PC, there are many free GUI based software available. A popular telnet/ssh client is PuTTY. You can dowload here PuTTY Website

Another popular ssh/sftp client is ssh.

Connecting to a remote Unix server from Linux & Unix

If your local machine is a Linux or Unix machine, you can use command line utilities, ssh or sftp, to connect to remote Unix/Linux servers. See Unix online reference manual pages ("man ssh" & "man sftp") for complete information. 

Using ssh to connect to a remote machine

  1. Run ssh command with remote login name and machine name.
  2. If this is the 1st time connecting to this remote host, ssh will create RSA key and save it in your local machine. Enter 'yes' to allow this task. 
  3. enter remote account password.
  4. Now, you are connected to the remote machine and can start works on the machine. 
  5. To return to local machine, type "exit".

Example: Use ssh from libra.sfsu.edu to connect to thecity.sfsu.edu.

Note: Comments have // surrounding them in the example below:

libra% ssh jwong@thecity     // Step 1 //

The authenticity of host 'thecity (130.212.3.51)' can't be established.

RSA key fingerprint is 3d:61:51:28:54:38:e5:fd:b7:a1:36:30:bd:01:1c:aa.

Are you sure you want to continue connecting (yes/no)? yes

// Step 2 //

Warning: Permanently added 'thecity,130.212.3.51' (RSA) to the list of known hosts.

jwong@thecity's password:    // Step 3 //

Last login: Sun Jun  6 18:18:30 2004 from libra.sfsu.edu

Sun Microsystems Inc.   SunOS 5.8       Generic February 2000

Sun Microsystems Inc.   SunOS 5.8       Generic February 2000

[jwong@thecity] ~:           // Step 4 //

Using sftp to connect to a remote machine

  1. Run sftp command with remote login name and machine name.
  2. Enter remote account password.
  3. Now, you are connected to the remote machine. You may use any sftp/ftp commands.
  4. To return to local machine, type "quit".

Example: Use sftp to transfer a file "jwong/pj2/p2.c" from remote machine "thecity" to current directory at local machine "libra".

Note: Comments have // surrounding them in the example below:

libra% sftp jwong@thecity // Step 1 //

Connecting to thecity...

jwong@thecity's password: // Step 2 // 

// Step 3 : sftp commands //

sftp> cd pj2              // change to directory pj2 //

sftp> ls                  // list files in pj2 //

.     ..    p2.c

sftp> get p2.c            // transfer file p2.c to the local machine //

Fetching /export/home/faculty/jwong/pj2/p2.c to p2.c

sftp> quit                // Step 4/ /

libra% ls                 // back to libra, list files at current directory//

p2.c

See ftp information from SFSU Division of Information Technology here.

Basic C/C++ Compilers & Compiling Information

C/C++ compilers
Type Compiler
GNU C/C++ compilers gcc or g++
SunOS/BSD C/C++ compiler cc or c++

Introduction to compiling C/C++ programs in remote server

  1. Use ssh to login to the remote server.
  2. Use a file editor to create program file, say proj1.cc, in your directory OR Use sftp to transfer the file proj1.cc from your local machine to your directory in the remote server.
  3. Use C++ compiler in the server to compile the program, i.e. type "g++ proj1.cc". If you don't have any errors, the compiler will translate your C++ program (proj1.cc) into an executable program in your current directory, called a.out (the default name).
  4. To run (execute) your C++ program, just type "./a.out". Now the statements in your C++ program proj1.cc will begin to execute.
  5. If you compile a new program lab2.cc. The compiler overwrote the executable of proj1.cc with the executable of lab2.cc, giving it the same default name "a.out". To save the executable program of proj1.cc under a different name instead of a.out, for example under the name proj1 type "g++ proj1.cc -o proj1". Similarly, to save the executable program of lab2.cc under a different name, lets say under the name lab2 type "g++ lab2.c -o lab2".
  6. Now to run the program proj1.cc just type ./proj1. To run the program lab2.cc just type ./lab2.

See Unix online manual "man g++" for complete information.