How to Compile and Run Programs With SSH
Secure shell (SSH) is a network protocol that encrypts transmissions to prevent anyone from intercepting your data. It is usually used to connect a local computer to a remote UNIX or Linux system, allowing you to run commands on those systems. For example, if you have a user account on a Linux system, you could use SSH to log in and compile and run source code. This is particularly useful if you are using a Windows machine, but your program is written for the UNIX or Linux operating systems.
Things You'll Need
- Local computer with SSH Client installed
- Remote computer with SSH server (often referred to as a shell account)
Start the SSH Client by clicking on its icon. If you are using a Windows PC, you will need to download an SSH Client. Linux, UNIX, and Mac OSX come with SSH clients built into them.
Enter the server address for the remote computer you have an account with. You need to enter this in the SSH client field marked "Server" or "Remote System." The exact wording depends on the software used. For example, the Windows program PuTTY uses the term "Host Name."
Type in your username and password in the SSH client fields marked "Username" and "Password."
Click on the "Connect" button to initiate the SSH session. A window appears and displays a command prompt. You have now logged in on the remote system and can execute commands.
Enter the command to compile your source code. This source code must be on the remote system, in your user directory. The exact command depends on the compiler you are using and the programming language in which your program is written. The following three examples show how to compile a C, C++ and Java source code files named "source.c", "source.cpp" and "source.java" into a program:gcc --o programName source.c g++ -o programName source.cppjavac source.java
Enter the command that executes your program. This requires that you enter the name of the program you compiled. In the case of the C and C++ program, the program name is "programName." In the case of the Java program, the program takes the same name as the source code file, so it is "source." Here are the commands necessary to run the C, C++, and Java programs:./programName./programNamejava source
Press the "Enter" key to execute the command. Your program will now run on the remote system.