Setting up my Dev Environment ECS 030 1 Command for SSHing into a CSIF Machine If you already have a terminal and already have a working ssh program (That is, you type ssh into the terminal and it doesn t say it cannot recognize the command), simply type in the following: ssh username@pcxx.cs.ucdavis.edu Replace username by your CAS Kerberos username and xx by a two-digit number (I checked 10 and 12 and they worked, but you can choose any between 1-60). Once successful, the terminal would prompt you to input your password. Type in your Kerberos password for CAS and you should be able to login. For logging out the ssh session, type logout or exit. 2 How to Install SSH 2.1 Windows 1. Go to https://www.cygwin.com and download the setup.exe. Make sure that you make the right choice for 32/64-bit. Remark. Briefly speaking, cygwin is something that emulates a Unix-like environment on Windows. It includes, among a lot of other things, a terminal program where you can execute Unix commands like cd, ls, etc.. 2. Double click the setup.exe and begin the installation. Choose the following options during the process: (a) Choose Install from Internet at Choose A Download Source page. (b) Choose a root directory yourself. This will be the place which the going-tobe installed cygwin bash treats as its own root. For example, if you specify C:\cygwin64 as your root directory, /home/james will in fact be located in C:\cygwin64\home\james. (c) Choose All Users (the other option should also work, even though I haven t tested it.). (d) Choose a local package direcotry. This is the place cygwin stores all the files that are necessary for emulating the unix environment. (e) Select Direct Connection. (f) Select an available download site from the provided list. Any of them should work. I simply chose the very first one: http://cygwin.mirror.constant.com (g) The installer will grab some package listing info from the site you chose, and then open a package setup window. This window allows you to specify which packages to install. 1
(h) Under Net category, find the openssh package and click the Skip field of it. Make sure it changes to a version number and the checkbox of the Bin? column is checked. Basically, you need to install this ssh implementation, so that you can execute the ssh command once the installation completes. (i) Leave everything else unchanged (that is, the default option). Click Next button. (j) Wait until the installation finishes. I experienced an error message of incomplete download the first time, but a second trial succeeded. 3. After installation of cygwin completes, find the Cygwin64 Terminal program and open it (it should appear in the start menu if you told the installer to include an icon in the start menu ). Now you can pretty much treat this terminal as a Unix one and since you already installed openssh, you can ssh into a CSIF machine directly. Another option to connect to CSIF is the use of PuTTy. This application is a dedicated SSH client. The installation steps and usage is very simple. 1. Go to http://www.chirak.greenend.org.uk/ sgtatham/putty/download.html and download putty.exe file according to your installation. 2. Launch PuTTy by double clicking on the downloaded file. 3. In the Host Name (or IP address) box, type pcxx.cs.ucdavis.edu. Replace xx by a two-digit number from 1 to 60. 4. A security alert should appear the first time you connect to any given box. This warning is just to inform you about the rsa2 key fingerprint of the machine. You can safely click Yes. 5. The terminal should ask you for a login user. Use you Kerberos user and password. 2
2.2 MAC OS X MAC OS X should include a built-in SSH client that you can use directly in the Terminal. Simply type ssh to see what happens. It might prompt you to install other developer tools. In that case, just follow the instructions. 2.3 Ubuntu (Other Debain-based System) To install ssh. Open a terminal and type the command: sudo apt-get install ssh The above command uses apt-get, the package manager on Debian-based linux systems to automatically download and install ssh. For linux distributions that s not Debian based, google and check the corresponding documentation to find out what package manager they use and use them to install ssh. 3 Developing locally If for some reason you can not have access to the CSIF machines, you can still work on your homeworks locally in your computers. Although before submission we request that you test it in a CSIF machine, because we can not guarantee that what ever you have in your environment is applicable for CSIF. And given we will grade in the later, it is your responsibility to guarantee it will compile and run in CSIF machines. 3.1 Windows Windows systems provide a C compiler that can be downloaded when installing Visual Studio; an Integrated Development Environment. Although VS is a very nice tool, it regularly introduces a lot of special files and characters that makes development in C very complicated when doing cross platform development. Therefore we do not suggest you use this tool. Nevertheless if you decided to install Cygwin, you are in great standing! Given that Cygwin is a Unix emulator, it also allows you to install a C/C++ compiler as another of the options in the installation process. You just have to select the gcc-core and gcc-g++ packages under devel. 3
3.2 MAC OS X Mac machines already have a C/C++ compiler. Unfortunately it is not the same as the one used in CSIF. While CSIF uses GCC compiler, Mac has clang installed. This will not cause a lot of issues for the initial part of the course, given that the code is pretty generic. But as we move forward into more advanced topics this could become an issue. Therefore the recommendation for this cases is that once you think you are done with your code in your machine, test it in a CSIF machine via SSH as described above. 3.3 Ubuntu (Other Debain-based System) Linux machines also already have a C/C++ compiler, the only thing you have to be aware is the version. But that should not be an issue. If for some reason your terminal does not finds the gcc command, you can install it using the following commands. sudo apt-get update sudo apt-get install gcc-5 g++-5 3.4 Compiling To compile your code remember that you have to be in the folder locaton where your source code is located. You should get there through the cd command. Once there you can call the compilation command gcc mycode.c -o mycode This command will compile mycode.c file and create the mycode executable. If you ommit the -o option the executable will be named a.out. To execute the file just call it as follows../mycode 4 Text Editor The selection of a text editor is crucial so you are not facing weird unforseen errors down the road. You should choose the most basic ones in order to avoid the insertion of hidden characters in the executable code that could cause problems at compilation time. Here are a list of some editors you can check and choose from the one you feel most comfortable with. Notepad (Win) - A simple out of the box solution that is already installed in Windows machines. Notepad++ (Win) - A free source code editor that provides some higlighting functionalities for syntax and some tools for transfering your files from your local machine to a CSIF box. Simple, clean and FREE! Sublime (All platforms) - One of the best development tools you could ever get! It is a very mature text editor that provides tons of tools that eases the development and sharing of your code. Provides support for multiple languages for syntax checking as well as customization options. But with great power comes great... cost; this is not a free tool, but definitively is worth every penny. 4
Atom.io (All platforms) - An open source version of Sublime developed by GitHub. Just as Sublime this tool grants you great tools and support for multiple languages and customizations and is FREE! But as such, it does present some bugs. Nevertheless it is supported by one of the most dynamic communities of open source, so if you report any issue, chances are that they will be solved in a reasonable amount of time. If you decide to work directly on the CSIF machines via SSH, you also have some options available. These are the vi editor, nano and emacs. These are console based Text Editors. If you decide to use any of these, you can google their usage, because it is not as simple as any of the others. Having said that, being able to use any of these editors tells a lot about your programming skills. 5 Transfering files to CSIF Once you are done developing and compiling your code in your machine, you should test it in the CSIF machines. To do so you must first be able to send your source code to CSIF boxes. To do so, there are two commands you can try sftp or scp. 5.1 sftp This is the Secure FTP command that allows a safe connection between your machine and a CSIF box to transfer files. To connect to any given box you have to run the command sftp <username>@pc##.cs.ucdavis.edu Remember to substitute < username > for your user name and ## with a number between 1 and 60. This command will open the ftp console that allows you to put files into the location that you connect or get files from the remote location to your local machine. It is important to notice 2 things: The location where the files will be taken in order to be able to put them in the remote machine is the working directory where you call the sftp command. For example: Assume I have a file sample.txt at \home\user\mydocs, and a file named mycode.c at \home\user\code. If I placed myself into mydocs folder, I would not be able to get the mycode.c file to put it into the server. In the sftp prompt you can also use all the filesystem navigation commands that will allow you to navigate to any given folder in the remote machine in order to pull it to your local machine. This also applies for the placing of files from my local machine. To exit the client you just have to type the command exit and the sftp client will be closed. 5.2 scp This is the Secure copy command. This tool allows you to send files to a remote location, but does not allows you to get files from there. This is a great way to send your code from your local machine to the remote CSIF boxes. To use it, you call it as follows 5
scp [list_of_files] <username>@pc##.cs.ucdavis.edu:<remote_destination_path> Remember to substitute < username > for your user name and ## with a number between 1 and 60. The list of files can be any number of filenames placed in the relative location to the working directory where the command is executed. The remote destination path should be the place where you want to put the files you are sending. 5.3 Visual interfaces For Windows users there are two tools that could help with this task. These are Filezilla and WinSCP. Both tools are just front ends for both SFTP and SCP commands that allow you to do drag and drop between both machines and avoids you to have to rewrite the commands multiple times with slight variations. The setup for either is pretty simple and is available in ther download sites. 6 Final Remark The best way to learn how to configure and develop stuff is always to try them out and google them. Therefore, if you experience some difficulties you should always think about what exactly your operation has done and googled accordingly, instead of directly asking some seniors for help (Do not understand what sudo means in the above? Google that!). Believe it or not, no programmers can live without google and stackoverflow! 6