How to Compile and Run Programs With SSH

Techwalla may earn compensation through affiliate links in this story. Learn more about our affiliate and product review process here.

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.

Advertisement

Step 1

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.

Video of the Day

Step 2

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."

Advertisement

Step 3

Type in your username and password in the SSH client fields marked "Username" and "Password."

Step 4

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.

Advertisement

Step 5

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:

Advertisement

gcc –o programName source.c g++ -o programName source.cpp javac source.java

Advertisement

Step 6

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:

Advertisement

./programName ./programName java source

Step 7

Press the "Enter" key to execute the command. Your program will now run on the remote system.

Video of the Day

Advertisement

Advertisement

references

Report an Issue

screenshot of the current page

Screenshot loading...