Skip to main content
Basic Programming In C
Basic Programming In C
Easy 1h30

Connecting to a School Machine

Difficulty: Easy

Without going into the details of the school network architecture, it is important to know that the single entry point is the server called portier.polytech-lille.fr. To connect, simply type in a terminal:

ssh your_login@portier.polytech-lille.fr -p2222

The -p2222 option corresponds to the port used which is not the default ssh port and must therefore be specified.

Once on this server, you have access to your documents but not all programs are necessarily installed (such as clang). In this case, the best option is to connect to a lab machine such as phinaertXY, reuzeXY, lydericXY, gedeonXY, gayantXY (where XY is a number from 01 to 16) to have access to all useful programs.

ssh gayant01

here, it is not necessary to specify your login because you are using the same one as on portier, and since the ssh port is the default one (22), it does not need to be specified.

Inside the Polytech Lille network, the server portier.polytech-lille.fr is also called arsenic or serveur-etu.polytech-lille.fr.

  1. Connect via ssh to arsenic.
  2. Verify that you are on arsenic via the command uname -n
  3. Check the other users connected to arsenic via the command w or who
  4. From arsenic, connect to a lab machine outside your room. Use uname -n and who again to verify that the previous commands are correct.

Copying Files From / To the Outside

Difficulty: Easy

On the Polytech Lille network, your files are accessible on any machine or server, so it is not necessary to copy your files from machine to machine. However, from/to the outside, it may sometimes be necessary to copy files. For this, use the command scp, whose syntax is as follows (run man scp for help):

scp source destination

which can be specified for the following use cases:

  • Copying a file projet.c (located for example on the desktop) from a Polytech Lille machine to your local machine (the trailing . represents the current directory)
scp -P2222 your_login@portier.polytech-lille.fr:~/Desktop/projet.c .
  • Copying the same file from your machine to Polytech Lille
scp -P2222 projet.c your_login@portier.polytech-lille.fr:~/Desktop/
  • Copying a directory projet (located for example in the Documents directory) from a Polytech Lille machine to your local machine (the trailing . represents the current directory)
scp -P2222 -r your_login@portier.polytech-lille.fr:~/Documents/projet .
  • Copying the same directory from your machine to Polytech Lille
scp -P2222 -r projet.c your_login@portier.polytech-lille.fr:~/Documents/
  1. If you have a laptop (or a smartphone with the termius app for example), try to transfer files from/to the Polytech Lille machines.

Using the GIT Version Control System

Difficulty: Easy

Preamble

GIT is a version control system that has become one of the standards for sharing digital resources. It has a large number of features and requires some learning to master. Here we will cover the most basic features that will allow you to easily share/save your files.

  1. Create a directory sauvegarde (the name does not matter) that will contain all the files you want to save.
  2. To structure your GIT repository, create a subdirectory programmation in your sauvegarde directory.
  3. Create a directory ed_info in your programmation directory
  4. Verify that you have the correct hierarchy with the tree command:
.
|-- Desktop
|-- ...
|-- public_html
`-- sauvegarde
    `-- programmation
        `-- ed_info

Basic GIT Configuration

  1. Type the following commands (replacing your name and surname with the correct values):
git config --global user.name "your name"
git config --global user.email firstname.lastname@polytech-lille.net
git config --global core.editor vim
git config --global push.default simple
git config --global color.decorate full
git config --global merge.conflictstyle diff3
  1. If you followed the previous question correctly, you should get by typing git config -l:
user.name=your name
user.email=firstname.lastname@polytech-lille.net
core.editor=vim
push.default=simple
color.decorate=full
merge.conflictstyle=diff3

Using GIT

  1. Take the file hello.c from the first ED Info:
#include <stdio.h>

int main ()
{
    printf ("Hello World !\n");
    return 0;
}

Place this file in the directory sauvegarde/programmation/ed_info.

  1. In the sauvegarde directory, type git init
  2. Type git status, verify that the message correctly indicates that the programmation directory is not tracked.
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    programmation/

nothing added to commit but untracked files present (use "git add" to track)
  1. Type git add programmation/ed_info/hello.c
  2. Type git status, verify that the message correctly indicates that the file hello.c is a new file.
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   programmation/ed_info/hello.c
  1. Type the command git commit -m "(feat) ed_info first commit". Your file is now saved in the GIT repository.
  2. In the file hello.c, replace the line containing printf with printf ("Hello SE3!\n");
  3. Type git status, verify that the message correctly indicates that the file hello.c is modified:
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   programmation/ed_info/hello.c

no changes added to commit (use "git add" and/or "git commit -a")
  1. Type git add sauvegarde/programmation/hello.c to indicate that you want to save these changes, then git commit -m "(fix) ed_info update printf" to validate the changes.
  2. Type git log --oneline to see the history of changes in your repository.
2306f11 (HEAD -> master) (fix) ed_info update printf
763b933 (feat) ed_info first commit
  1. Type git checkout abcdefg where abcdefg is the identifier before the first commit you made (in my case it is 763b933).
  2. Type cat auvegarde/programmation/hello.c and notice that you are displaying the first version of the C file.
  3. Type git checkout abcdefg where abcdefg is the identifier before the last commit you made (in my case it is 2306f11).
  4. Type cat auvegarde/programmation/hello.c and notice that you are displaying the latest version of the C file. You therefore see that with the git checkout command you can display the content of any saved version… not just the most recent one.

Adding a Server

Difficulty: Rx

For now, everything you have done is only accessible on the Polytech machines. The goal is to make it accessible from anywhere. We will therefore put your repository on a GIT server. There are several you can use such as:

  1. Create an account on one of these servers with your Polytech Lille email address (for example gitlab.com)
  2. Create a new empty project
  3. Then type in the terminal:
git remote add origin https://gitlab.com/your_login/your_project.git

there are two types of secure connections (https or ssh)… for security reasons, ssh outside of polytech is not possible

where you will have replaced your_login and your_project with the correct values.

  1. Then type git push origin master.
  2. Verify on gitlab.com that your project has been successfully transferred to the server.

Cloning a Repository

Difficulty: Rx

To verify that your repository is accessible everywhere, you can clone it. To do this:

  1. At the root of your account, create a directory sauv_temp
  2. Go to this directory
  3. Type git clone https://gitlab.com/your_login/your_project.git
  4. Notice that you have a copy of the repository and all saved versions.
  5. Modify the file hello.c
  6. Add / Commit / Push the file to the server
  7. Go to your sauvegarde directory
  8. Type the command git pull
  9. Notice that you have just retrieved the modified version

How to Work Between Two Computers

Once the repository is created on one machine (A) and cloned on another machine (B), the workflow is simple:

  1. Before modifying a file, do git pull to retrieve the latest changes (if any)
  2. Modify/add/delete your files…
  3. Add them for validation with git add
  4. Validate with (git commit -m "relevant message")
  5. Push the changes to the server with git push

Benefits of a Version Control System

Beyond synchronizing work across multiple computers, GIT allows sharing repositories (with your lab partner, an instructor…), easily reverting to a specific version of your documents (so there is no fear of saving a bad version or losing content)… Moreover, the gitlab and github environments add a set of very interesting features:

  • project management: task management, assignment to members, deliverable definition, documentation…
  • automation: automatic compilation, automatic tests, binary creation…

You will see these features in the next semester :)