CS252 : Frequently Asked Questions
Steven J. Zeil
This is a collection of questions (and answers!) that have arisen repeatedly in some of my past classes.
1 General CS252 Questions
1.1 Where can I get help on this course?
-
You can ask the instructor questions about general course material and about the assignments by email.
-
You can make use of the instructors’ office hours. See the syllabus for details.
-
Tutoring is available from the Computer Science Tutoring Center for both walk-in and by-Zoom visits.
1.2 How can I search quickly through the lecture notes?
Use the “Search” button on the Outline, Resources, and other directory pages on the course website.
1.3 “…you have not done the Try This exercises…”
As noted early in the course, first in Working from a Command Line, then The Unix File System, and yet again in Basic File Manipulation, you saw notices like this:
Throughout this course you will encounter sections labeled “Try This:”. That means that I really want you to log in and try the commands or procedures I describe, and observe and think about the results.
Some of the “Try This:” exercises will set up files and directories that will be used in later exercises, so skipping these early examples may lead to problems later on. Some of the assignments will also check to be sure that you have done the Try This exercises before attempting the assignment.
- For the same reason, you should not delete the directories and files set up during the Try This exercises. You are likely to need them again later.
You got this message because an assignment grading script detected that you had not done one or more of the Try Exercises. You will need to go back and do them.
In some cases, you may have done the Try This exercise but done them incorrectly. For example, if the exercise told you to create a directory ~/playing
and you instead created a directory ~/Playing
or ~/playng
or ~/UnixCourse/playing
, the grading script would conclude that you had not completed the exercise. There is simply no way that an automated program can account for the literally infinite number of possible misspellings and misplacings that people could possibly commit.
- In cases like this, you may be able to avoid redoing the entire Try This exercise by simply renaming or moving the offending directory or file to the correct value.
2 Connection and Login Issues
2.1 I can’t log in to CS Dept SSH servers
Try logging in to this page with your CS network credentials.
-
If you cannot log into that page, it is almost certainly a problem with your account credentials.
Common reasons:
- You don’t have an account on our network.
- You are typing the wrong login name. Remember that all student login names begin with “cs_” and use lower-case letters only.
- You forgot or mis-typed your password. (Some people will do this over and over again.)
- If you think you might not have the correct password, you can reset your password.
-
If you are able to log into that page, the same credentials (login name and password) should work for login in to the Linux servers.
If not, common reasons are:
- You are using the wrong type of client program to make the connection (e.g., trying to make an
ssh
connection using a web browser). - You are not connected to the CS VPN.
- You have the name of the server machine wrong. Make sure that you are giving the full name, including the “
.cs.odu.edu
” part. The safe bet is alwayslinux.cs.odu.edu
. - You have the wrong settings in the SSH client program you are using the make the connection or are giving the wrong
ssh
command.
- You are using the wrong type of client program to make the connection (e.g., trying to make an
If none of the above suggestions help, you will probably need to contact root@cs.odu.edu
for assistance. Be sure to tell them whether you were able to use your account to log into the web page linked above.
- Be sure to let them know that you have checked the items on this list.
- Tell them what kind of PC (operating system) you are trying to connect from.
- Tell them what SSH client software you are using.
- If it is command-based, tell them the exact command that you are typing to make your connection.
- If you are getting any kind of error message when you try to connect, tell them the full and exact text of that message.
2.2 I can’t log in to the CS VPN
Try logging in to this page with your CS network credentials.
-
If you cannot log into that page, the problem is definitely with your account. The possibilities are:
- You don’t have an account on our network.
- You are typing the wrong login name. Remember that all student login names begin with “cs_” and use lower-case letters only.
- You forgot or mis-typed your password. (Some people will do this over and over again.)
- If you think you might not have the correct password, you can reset your password.
-
If you are able to log into that page but still cannot log in to the VPN (using the same CS network credentials), then either
- Make an office hours appointment to meet with the instructor via Zoom and let them watch what you are doing.
- Or, contact
root@cs.odu.edu
for assistance.- Tell them what login name you are using.
- Do not give them your password.
- If you are getting any kind of error message when you try to connect, tell them the full and exact text of that message.
2.3 I can’t log in to CS252 web pages
Try logging in to this page with your CS network credentials.
-
If you cannot log into that page, the problem is definitely with your account. The possibilities are:
- You don’t have an account on our network.
- You are typing the wrong login name. Remember that all student login names begin with “cs_” and use lower-case letters only.
- You forgot or mis-typed your password. (Some people will do this over and over again.)
- If you think you might not have the correct password, you can reset your password.
If none of the above reasons seem to apply to you, then contact
root@cs.odu.edu
for assistance.* Tell them what login name you are using. * Do not give them your password. * If you are getting any kind of error message when you try to connect, tell them the _full and exact_ text of that message.
-
If you are able to log into that page but cannot log into CS252 pages, the most likely problem are:
-
You aren’t in the CS252 class for this semester. You can still read the lecture notes, but assignments and grade pages are limited to enrolled students.
-
You activated your CS network account within the past 24 hours.
Just wait.
-
You are on the web site for a previous semester.
Look at the top of the outline page. It says what semester that site is for. Is it the semester you want? (I leave old sites up as a convenience to former students.)
If you are looking for the current semester site, find the link in Canvas (if you are enrolled in the course) or get it from my home page.
-
2.4 “unable to connect, host does not exist”
You need to run the VPN before making your SSH connection.
2.5 “The authenticity of host … can’t be established.”
This is a normal and expected message whenever you connect to a new machine for the first time.
Just answer “yes” the to question about whether to continue connecting.
2.6 “POSSIBLE DNS SPOOFING DETECTED” or “REMOTE HOST IDENTIFICATION HAS CHANGED”
This message arises whenever the “hardware” that responds to connections to a particular machine name (e.g., linux.cs.odu.edu
) has changed. Your SSH client remembers the hardware IDs of your past connections and objects when the hardware appears to have changed.
This practice was instituted for SSH a long time ago and made sense at the time as protection against “DSN spoofing” (a.k.a.“man-in-the-middle”) attacks where someone on the network would insert their machine as a kind of wire-tap between you and your intended destination in order to spy out your login name and password.
It’s now pretty much just an annoyance because
- DNS spoofing is almost impossible if you are connecting via the VPN.
- In the modern world of cloud computing, the servers that respond to your connection attempts probably aren’t hardware at all, but “virtual machines” simulating the hardware, and those virtual machines may change at any time, far more frequently than anyone would ever purchase new hardware.
So what do you do?
-
Depending on your SSH client’s settings, it may have connected you anyway after issuing the warning. In that case, you can ignore the warning.
-
If it does not connect you, it will go on to tell you “Offending EDCSA key in filename:_lineNumber_”. This will be the file on your PC where the hardware IDs of past SSH connections are kept. For example, if you were connecting from a Windows 10 PC and your Windows login name is “
aStudent
”, you might seeOffending ECDSA key in C:\\Users\\aStudent/.ssh/known_hosts:1
telling you that the file is in
C:\Users\aStudent\.ssh\known_hosts
and the particular ID is in line 1 of that file.You can
- Edit that file (with Notepad or any other text editor) and delete that line, or
- Delete the file entirely. If the only machines that you do SSH connections to are CS Dept machines, this is probably the easier approach.
2.7 “Please contact your administrator or connect to EMS for license activation”
This message from the VPN client indicates that you installed the wrong version of the VPN software –– you have the free trial of the commercial package instead of the free open-source version.
Try uninstalling it and then reinstall. This time, when you visit the company page for the download, make sure that you go all the way to the bottom of the page and get the “Forticlient VPN”, not the full “Forticlient” package.
2.8 ssh-add
on Windows 10 says: communication with agent failed
-
Make sure that your agent is actually running.
- In the taskbar search area, type “services”. Select the “Run as administrator” option.
- Find the “OpenSSH Authentication Agent” service. Does it say that it is running? If not, start it. If it was running, proceed to the next step.
-
Some (older) builds of Windows 10 are missing a required component of the Agent service. That component is, however, in the SSH server optional feature.
- Open
Settings
. - Go to
Apps
, thenApps and Feature
, thenOptional Features
. - Find the entry for
OpenSSH Server
, click on it, and then clickInstall
.
Follow the on-screen instructions to complete the installation. 4. Leave this service on “Manual” so that it does not start automatically. You don’t actually want to run this service. You just need it to install the missing component.
Try
ssh-add
again. - Open
3 Common Unix Command Errors
3.1 “Permission denied”
In Unix, there are three basic kinds of permissions on every file:
-
Read permission: allows you (or the commands that you issue) to look at the contents of that file.
-
Write permission: allows you to alter the contents of a file.
-
Execute permission: allows you to execute or run the file as if it were a command or program.
(These same permissions also apply to directories, but the meanings are slightly different.)
So, in general, if you get a Permission denied error, it’s because you tried to read/write/execute a file for which you did not have the corresponding permission.
In CS252, there seem to be two very common reasons why people get this.
Common Reason 1: That’s not YOUR file
Many CS252 students will mistakenly try to create or edit files in one of my directories, e.g.:
cp foo.dat ~cs252/Assignments/wherever/
~cs252
is shorthand for /home/cs252
, the home for the cs252
class account, which is my directory, not yours.
- Your directories would be at paths starting with
~yourLoginName
or `/home/yourLoginName`` .
It should not surprise you that I don’t give you write permission on my files and directories.
Common Reason 2: That’s not a program or command
For ordinary data files that you create and work with, you will have read and write permission, but not execute permission, because you can’t execute ordinary data files. They’re data, not programs.
All Unix commands start with a command or program name, followed by zero or more parameters, most of which are going to be paths to files. Examples are:
cp /usr/include/math.h /usr/include/stdio.h ~/playing
mv ~/playing/math.h ~/playing/math0.h
g++ -o newProgram newProgram.cpp
./newProgram
But sometimes CS252 students forget to put in the command or program:
~/playing/math.h ~/playing/math0.h
Now, when I look at that, I wonder if the student wanted to copy the first file, rename it, delete the two files, open both files in an editor, or something else?
But when the command shell (the program that reads your typed commands and launches the actual program to carry out the command) looks at that, it assumes that you meant the first thing listed to be a command or program. So you wind up seeing something like:
~/playing/math.h ~/playing/math0.h
Permission denied
Why? Because the command shell assumed that you wanted it to execute ~/playing/math.h
, and that’s an ordinary data file, so you don’t have Execute permission on it.
See also: Try This (bad commands)
3.2 “No such file or directory”
This is actually pretty self-explanatory. You just issued a command containing a path to some file, and the path does not actually match any existing file.
Usually, this is just a matter of a simple spelling mistake. But it throws some people for a loop, because they just can’t seem to believe that they actually typed something wrong.
What can you do about it?
Look and see what the problem is.
ls
is one of the first Unix commands that you learned. Use it!
-
The message usually tells you what path it was trying to follow when it ran into trouble. For example,
No such file or directory: ~/UnixCourse/asst2/dataFile.txt
-
See if that file exists and if you have spelled it correctly:
ls ~/UnixCourse/asst2/dataFile.txt
-
If you get another
No such file or directory
, then try:ls ~/UnixCourse/asst2/
-
If you get a list of files, look to see if
dataFile.txt
is in there. Or maybe something spelled similarly, such asdatafile.txt
ordataFile.dat
. If, on the other hand, you still getNo such file or directory
, then try:ls ~/UnixCourse/
and look for
asst2
or something similar.- Keep going until you find the problem.
-
-
If the original error message does not tell you the path that it failed on, look at what you just typed.
If you just typed something like
./myProgram ~/UnixCourse/asst2/dataFile.txt
then use the same
ls
technique to check each path, first./myProgram
and then, if that proves to be OK, then~/UnixCourse/asst2/dataFile.txt
.
Diagnosing the reason for this error message should almost always be possible just by using the ls
command.
Avoid making the mistake in the first place.
No, I’m not being snarky. Remember that you can use the Tab key after typing a few characters of a file or directory name to ask the command shell to fill in as much of the remaining name as it can.
That’s a great way both to avoid misspelling things in the first place (because you aren’t typing as much) and also to catch misspellings as soon as you make them (because the command shell doesn’t find any valid file or directory names that start with the few letters you just typed).
A common problem responsible for many of these messages is not paying attention to the ways that we can abbreviate home directory paths.
There is a big difference between
~cs252/
and~/cs252/
~cs252/
means “the home account of thecs252
account”, and is a shorthand for/home/cs252
.~/cs252/
means “look in your own home directory for a directory namedcs252
” and is an abbreviation for/home/yourLoginName/cs252/
.
- And, honestly, it’s pretty unlikely that you even have a a directory named
cs252
.
3.3 Where do I find the file ~cs252/Assignments/fileAsst/foo.txt (…or some other lengthy path)?
How heavy is a 5 pound bag of flour?
Also, see 2.2 “No such file or directory” for the use of the ls
command to systematically search for files along a path.
3.4 “omitting directory”
This message comes from the cp
command when you try to copy a directory instead of a file or group of files.
The cp
command, under normal circumstances, copies only ordinary files and not directories. It is possible to change this behavior, but because copying entire directory structures is somewhat risky (you can waste a lot of storage with some simple mistakes), it’s turned off by default.
-
Most of the times when I see students getting the “directory omitted” error, it’s because they use the directory name when they should have named a file or a group of files inside that directory.
It’s as if I gave you a box of cookies and, instead of opening the box and eating the cookies, you instead chewed on the cardboard box itself (and then complained about the bland taste).
-
The “fix” in most cases is to add an appropriate wildcard expression after the directory path that describes which files form that directory you actually want.
-
If you want all the files, the wildcard expression is simply “
*
”.
-
3.5 cp: missing destination file operand
Look at the basic definition of the cp
command.
In it’s simplest form, it requires two pieces of information (command arguments). One is what you want to copy, the source. The other is where you want to copy it to, the destination. There are more elaborate forms of cp
as well, in which you give a whole list of files to copy. But you still will always need to end a cp
command with the destination.
Look now at all the uses of cp in the Try This exercises in that same lesson. (Just hit Ctrl-f and search the page for “cp”.) They all exhibit that pattern.
You’ve only given one piece of information in your command, the source. You are, as the error message states, missing the destination operand.
3.6 I get time-out errors when trying to connect to a server
Quite a few possibilities:
-
You are trying to connect to the wrong machine, or requesting a service of a machine that does not provide that service.
For example, if you try to make an ssh connection to
linux
, the connection will time out because “linux
” is not the (full) name of a machine on the Internet. (“linux.cs.odu.edu
” is a proper name of a machine.)If you try to make an ssh connection to
vcportal.cs.odu.edu
, the request will time out because, although that machine exists, but it’s not anssh
server and isn’t even listening to the the ports used for incoming ssh connections. -
You aren’t waiting long enough. Look at the settings you are using in your client program for connecting to the machine. If you see a short time-out, you might want to try allowing more time.
This seems to be a common problem with the sftp clients FileZilla and WinSCP, which by default time out after a few seconds. Often, that’s just not long enough.
-
Your own network connection may be down. See if you can connect to other internet services such as your favorite websites.
-
Try waiting a while and then connecting again. If ODU has suffered a power outage, we have backup power systems that usually cut in nearly immediately. Machines may need to reboot, but that’s a matter of minutes at most.
-
ODU might have suffered a massive Internet disconnect. Try using a web browser to visit the CS Dept home page. If it’s unreachable, other services may be unreachable as well.
-
See if you can read the ODU CS machines at all. Open a terminal window on your PC (Windows users: click in the search bar and type “cmd”). Give the command:
ping -n 4 -w 10000 linux.cs.odu.edu
This will check to see if you can reach the Linux machines at all and how long it takes. If the output does not indicate that you are receiving a reply, then there is a problem with the network connection between you and ODU. It might be at the ODU end. It might be at your end. it might be somewhere in between.
-
The machine might be down. You can report this to
root@cs.odu.edu
. -
Do you have firewall software installed on your PC? If so, try disabling it temporarily and try connecting again. If that works, reconfigure the firewall to allow outgoing connections on port 22.
-
You certainly will have a firewall built in to the router that connects you to your Internet Service Provider. If you know how to do so, check to see if it is blocking outgoing connections on port 22. (Note that blocking incoming connections is normal, but some people in a fit of over-zealousness block outgoing connections as well.)
A roundabout way to check this, if your PC is a laptop, is to use someone else’s WiFi. Visit a public library or school or a coffee shop that offers free WiFi and see if you can connect from the parking lot.
-
Try connecting to the CS Dept VPN, and then try connecting to the CS Linux servers again.
-
Finally, there is a possibility that your IP address has been blacklisted by the ODU CS security filters, presumably because of a pattern of network connection attempts that resembled attempted hacking. (This could be because your PC or some PC on your home network has been infected with malware that is attempting to spread itself. It is also true that most Internet Service Providers periodically reassign and recycle IP addresses, so your current IP address could be blacklisted because of someone else’s past misbehavior.)
Look up your own IP address and email the CS systems staff at
root@cs.odu.edu
. Describe the problem to them. Tell them your CS login name, your IP address, what machine you are trying to connect to, and what ssh/sftp client you are using. Tell them about the steps you have performed above to diagnose the problem and what you have observed.
4 Managing Your Account Directories
4.1 I have files in my directories that I don’t own and can’t delete.
If an ls -l
command reveals to you that you have some files or directories that belong to me, to ~cs252
or someone else in your account area, there’s a good chance that you won’t be able to delete them.
As far as I know, the only way this happens is because you tried to copy files using “
cp -a
”. This may be a good time to remind you that:
- As a general rule, everything you need to solve the assignments will be something that is covered in my lecture notes and that I have asked you to practice with in the “Try This” exercises.
- Avoid the temptation to go hunting up strange commands and command options on the internet or even in the Linux man pages in the belief that the magic answer is hidden out there somewhere.
The “-a” option of the “cp” command is definitely not something covered in the Lecture Notes nor that you have practiced with in the Try This exercises. It isn’t covered because it is rarely useful and often leads to exactly this sort of problem.
If you encounter this problem and can’t delete the errant files, the bad news is that “owner” of the files probably won’t be able to delete them either. That’s because although the owner likely has the permissions to manipulate those files, the owner probably does not have permission to navigate through your directories to where those files are located, and probably does not have permission to delete things from your directories either.
Here’s what you need to do:
-
Use the
mv
to rename the file/directory to something that won’t interfere with your work, e.g., “garbage” or “deleteThis”. -
Send email to
root@cs.odu.edu
explaining the problem. Ask them to delete the file/directory. Make sure that you give them the absolute path to the renamed file or directory that you want removed.
A final word of advice. If you are asked to copy all files from a directory, that is not the same thing as copying the directory. As suggested elsewhere, this is like the difference between eating the cookies in a box versus chewing on the cardboard box itself. To copy the files from a directory, the command is
cp path-to-source-directory/* path-to-destination-directory/
The *
is the wildcard pattern that matches any string of characters.
4.2 I deleted some files by accident. Can I get them back?
Files on our Linux servers are backed up every six hours. So if these files have existed for a while, you can recover them, although you may lose any changes you made since the last backup.
-
If it has been less than a month since you deleted the files, you can recover them yourself. You will find the basic instructions here.
A step-by-step procedure is to
cd
to the directory from which you deleted the files.- Then
cd
into.snapshot
(take note of the ‘.’) and do anls
.
You will see a list of dates and times at which snapshots are available. - If necessary,
ls
through some of those date-time directories to find the most recent snapshot containing your missing files. cd
into the desired date-time directory.- Copy the missing files back to the original directory.
-
For example. if you accidentally deleted the file
foobar.txt
, you could saycp -a foobar.txt ../..
(The -a option, which normally I do not recommend using, will preserve the original timestamp and permissions on the file.)
-
If you deleted entire directories, add a “-r” option to your
cp
command. For example, if you accidentally deleted the directorybaz
and all of its contents, you could saycp -a -r baz ../..
-
If you deleted multiple files from the directory, use wildcards in your
cp
statement. For example, if you deleted all of the files,cp -a * ../..
if none of the deleted files were directories, or
cp -a -r * ../..
if some of them were.
On the other hand, if you only deleted the
.cpp
files, you would saycp -a *.cpp ../..
-
-
If it has been more than a month since you deleted the files, send an e-mail to
root@cs.odu.edu
describing precisely the files you want recovered, and the date from which to recover them.
4.3 “Quota Exceeded”
If you get this message after running a command on one of our Linux servers, you need to reduce the amount of file storage you are using.
There’s a good chance that there are a relatively small number of files clogging up your account area. You may well discover that you don’t need them, or even know that you had them. Common problems are:
-
If you’ve ever written a program that got caught in an infinite loop (and what programmer hasn’t?), and if that loop was writing output to a file, you may have created a huge output file before you decided to kill the program.
-
If you’ve ever written a program that got crashed, it may have left behind a block of debugging info in a file named
X.stackdump
, where “X” is the name of the program that crashed. These stackdump files can be huge. And it’s easy to wind up with a whole collection of them.Other crashing programs can also leave stackdump programs behind.
-
Every now and then, I see someone inadvertently write a
cp
command that tries to copy every file and directory in their home directory into a location within their account area or, worse, every file on the machine, from/
on down, into a location somewhere in their account area.
This command will list the 10 largest files in your account area:
find -H ~ -xdev -type f -printf '%s %p\n' | sort -nr | head -10
(The find
command searches through your home directory printing all the files in the format “size filepath”, the sort
command sorts by the file size (largest first), and the head
command selects the first 10 lines. If you want a longer listing, change the “10” at the end to a larger number.)
This command is useful if you have a small number of very large files clogging up your account area.
What if, instead, you have a large number of relatively small files filling up your quota? This command will list the 10 largest files and directories in your account area:
du ~ -a | sort -nr | head -10
Not surprisingly, you will probably see your home directory listed first, because it contains everything else. Again, if you need a longer listing, change the “10” at the end to a larger number.
Once you have located the files that are giving you problems, use the rm
command to remove them. If you are unable to do so, use “ls -l” to check your permissions on those files and change the permissions if necessary. If you still cannot remove the offending files, you may need to contact root@cs.odu.edu
and ask them to do so.
4.4 “No space left on device”
This could be caused by your using more storage than is permitted for your account. It can also be caused by other people using up all available space on the disk.
Log in and give the command
df ~
This will print a report on available space on the drive where you account resides. If the “Available” number is near zero, report this to root@cs.odu.edu.
Otherwise, follow the suggestions in this question to trim your own use of files.
5 Git and SSH key issues
5.1 ssh complains about an “UNPROTECTED PRIVATE KEY FILE!”
Your private key file should be readable (and writable) by you alone.
-
If you are using ssh from Windows WSL
- Keep the private key in the WSL area: preferably in
~/.ssh
- Use the
chmod
command to change its permissions to600
- Keep the private key in the WSL area: preferably in
-
If your private key is on a Linux/MacOS machine, or in Windows CygWin
-
Use the
chmod
command to change its permissions to600
-
-
If your private key is in ordinary Windows
- Use the Windows File Explorer to display the directory containing the key.
- Right-click on the key file and select
Properties
. - Go to the
Security
tab. ClickEdit
to change the permissions. - Make sure that you (ie., your Windows login name) have full access ot the file (all Allow boxes checked, even if they are greyed out).
Deny
permission to all other User names (leaveSYSTEM
alone). If your own Windows login is an Administrator account (common on most personal PCs), you should allow the permissions forAdministrators
.- Hit OK until you are out of the Properties.
5.2 SSH prompts me for a password instead of using my key
The most likely reasons for this are
- You have not properly authorized the public half of your key.
- You aren’t running an SSH agent on your own PC.
- You have not added the private half of your key to the agent.
- You did not use the “
ssh -A
” option to connect to the remote Linux machine, or you are in X2Go, which does not support that option.
Troubleshooting
On your local PC, give the command
ssh-add -l
If it complains that it can’t contact a server, then your problem is #2 above. Refer to Starting an Agent….
If it does not complain, but does not list your GitHub SSH key (or any key at all), then your problem is #3 above. refer to Adding Keys to the Agent.
If it lists your keys, then, in your SSH session to the remote Linux machine, give the same command
ssh-add -l
If it complains that it can’t contact a server or fails to list your key, then the problem is #4 above. Refer to Cloning an Existing Project.
If that command on the remote machine does list your key, then your problem is likely #1 above. Refer to Authorizing Keys.
5.3 Git prompts me for a password when I try to clone, push, or pull.
These three actions (clone, push, & pull) are the ones that communicate directly with GitHub. Other actions (e.g., add, commit) work on your local copy of the repository only.
You need to provide an SSH key to log into GitHub for those three actions. If you are prompted for a password, it’s a sign that your SSH key was not seen or was rejected.
The most likely reasons for this are
- You have not properly registered the public half of your key with GitHub.
- You aren’t running an SSH agent on your own PC.
- You have not added the private half of your key to the agent.
- You did not use the “
ssh -A
” option to connect to the remote Linux machine, or you are in X2Go, which does not support that option.- If you are doing remote development with VSCode, you may have forgotten the ForwardAgent parameter in your connection setup.
Troubleshooting
On your local PC, give the command
ssh-add -l
If it complains that it can’t contact a server, then your problem is #2 above. Refer to Starting an Agent….
If it does not complain, but does not list your GitHub SSH key (or any key at all), then your problem is #3 above. refer to Adding Keys to the Agent.
If it does list your keys, then open an SSH session to the remote Linux machine (or use the VSCode terminal if you are doing remote development with VSCode), and give the same command to the remote server:
ssh-add -l
If it complains that it can’t contact a server or fails to list your key, then the problem is #4 above. Refer to Cloning an Existing Project.
If that command on the remote machine does list your key, then your problem is likely #1 above. Refer to Logging in to GitHub.
5.4 Git tells me “Permission denied (public key).”
Either
- you are trying to clone a private repository belonging to someone else, or
- GitHub is not able to log in with your SSH key.
The most likely reasons for GitHub to have problems with your SSH key are
- You have not properly registered the public half of your key with GitHub.
- You aren’t running an SSH agent on your own PC.
- You have not added the private half of your key to the agent.
- You did not use the “
ssh -A
” option to connect to the remote Linux machine, or you are in X2Go, which does not support that option.- If you are doing remote development with VSCode, you may have forgotten the ForwardAgent parameter in your connection setup.
Troubleshooting
On your local PC, give the command
ssh-add -l
If it complains that it can’t contact a server, then your problem is #2 above. Refer to Starting an Agent….
If it does not complain, but does not list your GitHub SSH key (or any key at all), then your problem is #3 above. refer to Adding Keys to the Agent.
If it does list your keys, then open an SSH session to the remote Linux machine (or use the VSCode terminal if you are doing remote development with VSCode), and give the same command to the remote server:
ssh-add -l
If it complains that it can’t contact a server or fails to list your key, then the problem is #4 above. Refer to Cloning an Existing Project.
If that command on the remote machine does list your key, then your problem is likely #1 above. Refer to Logging in to GitHub.
6 Eclipse & VSCode Issues
6.1 Eclipse says that your workspace is currently in use.
If you drop your connection to an X2Go session either accidentally (e.g., the network failed) or deliberately (you closed the connection without shutting down your running programs first), X2Go preserves your session. When you reconnect to that same server, X2Go will bring up the windows that you had open when you left.
If you get this message from Eclipse, you probably have an Eclipse session still running on a different server. Select “Choose” and then “Cancel” to get out of this. Then reconnect X2Go via the server you used earlier. If you don’t remember which server that was, you may need to try all of them until you find the one that pops up your old Eclipse window.
This is, by the way, one reason why I recommend configuring your X2Go client to go to specific servers instead of to the switcher linux.cs.odu.edu
.
6.2 I created an Eclipse Java project with the wrong settings. How do I re-do it?
A lot depends on just how much is wrong. Minor problems can be fixed by right-clicking on the project name, selecting “Build path”, then “Configure Build Path” and adjusting your settings from there.
For major issues, it is often easier to to ask Eclipse to re-examine your project and deduce your settings, though you may still need to make minor tweaks to the build path afterwards.
To do this:
-
In Eclipse, delete your project. Do not check the box to delete the project contents. You just want Eclipse to stop tracking the project.
-
In a terminal session,
cd
to the project directory and locate and delete the.project
and `.classpath`` files. These are where Eclipse stored your old project settings.-
Take note that these file names start with “
.
”, which means that in Linux and MacOS these files are “hidden” by default. You can spot them by adding the “-a” to your “ls” commands.
-
-
Back in Eclipse, create or import your project again.
6.3 How do I supply command line parameters when executing my programs?
Often you will be writing programs that take “command line parameters” as part of their inputs.
Of course, if you are executing a program from the command line, you just type the parameter values on the command line (hence the name!), e.g.,
java MyPackage.MyProgram ../testData/myTestData.txt 23
But what if you are launching your program from an IDE?
6.3.1 Eclipse
-
After you have successfully compiled your code, right-click on the Java class that contains your main function. Then, from the Run menu, select Run configurations…
You’ll see a list of different project types, one of which should be “Java Application”.
-
Underneath that, you might already have a configuration for this program (Clicking on a configuration will show you what project and what Java class it is associated with.)
-
If not, select “Java Application”, then at the top of the column click on the icon for “
New launch configuration
”.
-
-
On the “
Arguments
” tab, enter your command line parameters into the “Program Arguments
” box. -
Click
Run
to save these arguments and launch your program.
6.3.2 VSCode
The first time that you want to run a Java program with command line parameters requires some preparation.
-
Open a Java file in the editor, preferably the one that contains the
main
function for the program that you want to run. -
From the
Run
menu, selectAdd Configuration...
A file
.vscode/launch.json
will be created and opened in your editor. You should see something that looks like this:{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "java", "name": "Current File", "request": "launch", "mainClass": "${file}" }, { "type": "java", "name": "MainProgram", "request": "launch", "mainClass": "cs252.MainProgram", "projectName": "mainprogram_528ad334" } ] }
This creates two or more run configurations, the first one (highlighted above) to run whatever Java file you have open and the rest to run Java files that have a
main
function. -
Delete the highlighted option. It creates more confusion (IMO) than it’s worth.
- Go to the configuration that names the class with the
main
function that you want to run. Add a line of the form"args": [
list_of_command_line_parameters],
with each parameter in the list inside quote
" "
and separated from one another by commas.For example, if you want to run the equivalent of
java cs252.MainProgram abc 123
you should edit
launch.json
like this:{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "java", "name": "MainProgram", "request": "launch", "mainClass": "cs252.MainProgram", "args": ["abc", "123"], "projectName": "mainprogram_528ad334" } ] }
Save your changes to
.vscode/launch.json
-
Now you should be able to run the program, with those parameters, either from the VSCode debugger or by right-clicking on the Java file and selecting
Run Java
.
6.4 Eclipse “New Project” does not show an option to create C++ projects
There is a bug in the current installation of Eclipse on our Linux servers that can cause this problem if you switch from one Linux server to another between Eclipse sessions.
- One fix is to simply reconnect to the same server that you used before, and to consistently use that server for working in Eclipse.
- Alternatively, close down eclipse, do
rm -r ~/.eclipse
and then restart Eclipse. If you have customized your Eclipse settings, you may lose your customizations by doing this.
- If neither of the above works for you, you can run my own installation of Eclipse via the command
~zeil/src/eclipse/eclipse &
6.5 Eclipse will not reopen C++ files, complains about missing cdt
components.
There is a bug in the current installation of Eclipse on our Linux servers that can cause this problem if you switch from one Linux server to another between Eclipse sessions.
- One fix is to simply reconnect to the same server that you used before, and to consistently use that server for working in Eclipse.
- Alternatively, close down eclipse, do
rm -r ~/.eclipse
and then restart Eclipse. If you have customized your Eclipse settings, you may lose your customizations by doing this.
- If neither of the above works for you, you can run my own installation of Eclipse via the command
~zeil/src/eclipse/eclipse &
7 C++ & General Programming Questions
7.1 What’s all this “foo” and “bar” stuff?
There is a long-standing tradition in computer science of using certain words as sample variable/function/whatever names. Just as a mathematician might use “x” or “y” whenever an arbitrary variable name is needed, computer scientists tend to use “foo”, “bar”, and “baz”, in that order. Check out this entry in the Hacker’s Dictionary for a discussion of the origin of these terms.
7.2 Why do compilers’ error messages often give the wrong line number, or even the wrong file?
A compiler can only report where it detected a problem. Where you actually committed a mistake may be someplace entirely different.
Let’s look at a simple example:
7.2.1 Example 1
Assume that the compiler has read part, but not all, of your program. The part that has just been read contains a syntax error. For the sake of example, let’s say you wrote:
x = y + 2 * x // missing semi-colon
Now, when the compiler has read only the first line, it can’t tell that anything is wrong. That’s because it is still possible, as far as the compiler knows, that the next line of source code will start with a “;” or some other valid expression. So the compiler will never complain about this line.
If the compiler reads another line, and discovers that you had written:
x = y + 2 * x // missing semi-colon
++i;
The compiler knows that you did something wrong. But it still won’t conclude that there’s a missing semi-colon. For all it knows, the “real” mistake might be that you meant to type “+” instead of “++”.
7.2.2 Example 2
Now, things can be much worse. Suppose that inside a file foo.h
you write
class Foo {
⋮
Foo();
int f();
// missing };
and inside another file, bar.cpp
, you write
#include "foo.h"
int g() { ... }
void h(Foo) { ... }
int main() { ... }
Where will the error be reported? Probably on the very last line of bar.cpp
! Why? Because until then, it’s still possible, as far as the compiler knows, for the missing “};
” to come, in which case g
, h
, and main
would just be additional member functions of the class Foo
.
So, with most error messages, you know only that the real mistake occurred on the line reported or earlier, possibly even in an earlier-\#include
’d file.
7.3 I’m getting “…undeclared…” or “No match for…” errors when I compile C++ code
In C++, most things that you give names to (e.g., variables, functions, etc.) need to be both declared and defined.
You declare something by introducing its name and sating what type of thing it is. For example:
int foo (int x);
declares a function named “foo” and a parameter named “x”.
The rule in C++ is that you must declare names before your try to use them.
If you get a message that says that something is undefined or is not a match for the name appearing in some line of code, then you have either
- forgot to declare it before using it, or
- misspelled the name in the declaration, or
- misspelled the name when you later used it.
7.4 I’m getting “undefined reference to…” errors when I compile C++ code
In C++, most things that you give names to (e.g., variables, functions, etc.) need to be both declared and defined.
Your define something by supplying its name, description, and the initial value, function body, or other information that “completes” everything the compiler needs to know about that named thing. For example:
int foo (int x)
{
return x + 2;
}
defines the function named “foo”.
The rule in C++ is that you must define things exactly once in all of the compilation units (.cpp files) that make up your program before producing your final executable.
If you are getting a message saying that some name is undefined, it means that the compiler/linker could not find that definition when it tried to generate your final executable program.
Most often, this seems to happen with functions. The possible causes are:
- You have forgotten to supply a body for a function.
- You misspelled the name of the function in the body, so the compiler thinks you are supplying a body for a completely different function.
- You forgot to compile the
.cpp
file that has the function body or forgot to include the resulting.o
file when you linked the rest of the program together. - You gave the wrong compilation command, and told
g++
to treat a single.cpp
file as the entire program even though there are multiple.cpp
files making up the program.
8 Miscellaneous
8.1 How do I type the M- key in emacs?
This is covered in the emacs tutorial, but the basic answer is that it depends on what kind of PC you are one and on what ssh client or X server software you are using. But there are several options, and at least one of those is guaranteed to work:
"M-<chr> means hold the META or EDIT or ALT key down while typing <chr>.
If there is no META, EDIT or ALT key, instead press and release the
ESC key and then type <chr>. We write <ESC> for the ESC key."
Also take note that if you have OS/mode or Alt keys on both sides of the space bar, some ssh clients and X servers will treat them differently, often reserving one for issuing commands to your PC’s operating system while using the other to send things through the ssh connection to the remote machine. So you may need to try both the left and the right keys separately.
When in doubt, however, the Esc key always works. But It’s not a modifier like Shift or Ctrl that gets held down while you type the other keys. You type Esc and release it before giving the rest of the character sequence.
8.2 How do I examine the values of pointers in a debugger?
First, understand that a pointer is an address. It is usually printed as a hexadecimal (base 16) number. A common convention for displaying hexadecimal numbers is to print them immediately after “0x
”, so, for example, 0x10A
would denote the number 266 ($1 * 16^2 + 0 * 16 + 10$).
If a pointer value is shown as 0x0
, it is null and doesn’t point to anything at all.
If a pointer has a non-zero, non-null value, you often want to see the data that it points to.
- In the Eclipse and nemiver debuggers, simply clicking on the small arrow next to the pointer will ask the debugger to show you what the pointer points to.
- In Code::Blocks and emacs/gdb-mode, you need to type out the C++ expression that means “fetch what this points to”. This is called dereferencing the pointer and is accomplished via the
*
operator.- In emacs/gdb-mode you use this expression with a
p
(print) command. - In Code::Blocks, you enter this expression in the “Watches” window.
For example, if
x.next
is a pointer, you could dereference it as*(x.next)
. - In emacs/gdb-mode you use this expression with a
8.3 In regular expressions, how can I match a string of exactly K characters?
K might be $3$, $4$, $5$, or any fixed value.
- Write a pattern that matches at least K characters.
- Use
^
to anchor the first character of your pattern to the beginning of the string. - Use ‘$’ to anchor the last character of your pattern to the end of the string.
Because if you match K characters somewhere in a string, and the first character you match is at the start of the string and the last character that you match is at the end of the string, then “obviously” the string can only be K characters long.
For example, if you wanted to match only strings of length 3 in which the first character is an upper-case letter and the last character is a lower-case letter, you could use the regular expression
^[A-Z].[a-z]$
because
[A-Z]
matches one character that must be an upper case letter,- . matches any one character,
[a-z]
matches one character that must be an lower case letter,- the
^
means that the upper-case character must be at the start of the string, and - the
$
means that the lower-case character must be at the end of the string.
Surprisingly, a lot of people seem to get the idea of using the ^
or the $
, but don’t think to use both.
8.4 I cannot install software on my Mac: “developer cannot be verified”
That’s a common problem when using almost any open-source software on MacOS. The solution is covered in the macOS User Guide.
8.5 How do I unpack a Zip file on my own PC?
If you are running Windows…
Open the Windows File Explorer, navigate to the directory containing the Zip file, and double-click on the Zip file to open it. You can now copy-and-paste the files inside the Zip archive to any regular directory on your PC.
If you are running MacOS…
Open the Mac Finder, navigate to the directory containing the Zip file, and double-click on the Zip file to open it. You can now copy-and-paste the files inside the Zip archive to any regular directory on your PC.
If you are running Linux…
cd
to the directory containing the .zip
file, and give the command
unzip -l name-of-the-zip-file.zip
to see what is inside the file.
Give the command
unzip -l name-of-the-zip-file.zip
to unpack the contents into your current working directory, or give the command
unzip -l name-of-the-zip-file.zip -d path-to-another-directory
to unpack the contents into some other directory.
8.6 On the exam, why didn’t I get partial credit for the multiple-answer questions?
On multiple-answer (choose all that apply) questions:
- It is equally important to choose the correct items and to not choose the incorrect items. (Otherwise you could always get a perfect core by selecting all of the items.)
- Partial credit is calculated by dividing the total points possible by the number of correct answers for the question. That’s how much you gain for each correct answer selected and how much you lose for each incorrect answer selected.
- For example, if a question has 5 options, two of which are correct, each of those two correct answers earns 50% of the points, but each incorrect answer selected subtracts 50%.
- If a question has 3 options, only one of which is correct, then that option is worth 100% of the points, and selecting either of the incorrect options will subtract 100%.