SCP & SSH by Mac Terminal CLI or Command Line Interface
Using the SSH CLI for Tux
A CLI is a Command Line
Interface. No pictures, no graphics, just text. A CLI Command is what
you would type at the command line prompt.
DO NOT ssh into Tux in the same window that you use the SCP command in!
If you ssh into Tux, you won't be able to scp to/from your local computer (normally).
SSH CLI Commands below:
Command (use if you have issues with above):
ssh yourTuxUserid@tux.cs.drexel.edu
Example:
ssh mjg88@tux.cs.drexel.edu
- Connect to remote Tux host.
- A
password prompt will then be displayed.
- Please type in your password
- Your password will remain invisible the whole time.
- Once you type in your password, simply hit Enter or Return on your keyboard.
SCP Video Instructions
https://1513041.mediaspace.kaltura.com/media/SCP+by+Mac+Terminal+CLI+or+Command+Line+Interface/1_501ss02wSCP Can Overwrite/Delete Files & Folders
If you scp a file to Tux or your computer,
and that file name already exists where you are copying it to,
the file you copy overwrites a file with the same name.
If you scp an entire folder to Tux or your computer,
and that folder name already exists where you are copying it to,
the folder you copy overwrites the folder with the same name.
So...
If a file or sub-folder existed in the folder you copied to,
but not in the folder you copied from,
the file or sub-folder gets deleted from the folder you copy to.
So... Back-Up Your Files, Folder, and Data!!
MAKE BACKUPS OR COPIES OF YOUR IMPORTANT FILES!!!
Google the cp command for Linux.
Frequently make copies of files and folders in a SEPARATE folder with a DIFFERENT NAME!!!!
Or use OneDrive. See Office 365 -- OneDrive.
Or Github or Gitlab or some other solution.
SCP Quick Tips
- SCP or Secure Copy Protocol lets you securely copy files or folders between two machines/computers/servers/hosts.
- scp is the CLI command, or Command Line Interface command.
- scp needs you to specify the source you are copying from & destination to copy to.
So...
scp source_file_or_folder destination_file_or_folder - Specify source (where you copy from) 1st & destination (where you copy to) 2nd.
- Always refer to the machine you are *not on* with userid@host:/file/folder/path
- Or for some, the old method of: userid@host:/file/folder/path
- Always refer to the machine you are *on* with just /file/folder/path
- Check file paths. Mistyped file paths are a very common error.
- Do NOT ssh into Tux BEFORE you use scp!
Do NOT ssh into Tux to scp!
DO NOT use the ssh command at all in the same Terminal window when you use scp. If you ssh into Tux, you won't be able to scp to/from your local computer.
Otherwise...
Your computer would need to be set up as a host on a network,
and you'd need to know the computer hostname,
and a userid that can login via the internet.
You know Tux's hostname and your own username on tux.
Using SCP
Below are example of how to use SCP.
For ALL of these examples:
- "MacUserID" is your Mac login userid.
- "yourTuxUserid" is your Tux userid.
- Do not use mjg88 as either your Tux or Mac login userid.
- mjg88 is an example for either userid.
- pwd command prints outs (shows you) your current folder (working directory) and the full file or folder path of it
- ls command lists the files or folders in the current folder (working directory)
- cd /path/to/folder changes directory, or navigates to, a different directory or folder
- cd sub_folder_name changes directory, or navigates to, a sub-directory or sub-folder of the current folder or directory you are in.
- cd ../ changes to the parent directory or goes up one folder level
- cd changes directory to your home directory or folder
Example 1
Command:
scp yourTuxUserid@tux.cs.drexel.edu:temp.txt /Users/MacUserId/Desktop/
Command example:
scp mjg88@tux.cs.drexel.edu:temp.txt /Users/mjg88/Desktop/
- Copying temp.txt from your remote Tux home folder to your local Mac computer's desktop folder.
Example 2
Command:
scp yourTuxUserid@tux.cs.drexel.edu:temp.txt
Command example:
scp mjg88@tux.cs.drexel.edu:temp.txt
- Copying a file named temp.txt from your remote Tux home folder to your local Mac computer.
- You already navigated in the Terminal CLI on your Mac to the folder (directory) that you want to copy the file to.
- You are not renaming the file.
- So you do not need to specify the destination file or file path.
Example 3
Command:
scp temp.txt yourTuxUserid@tux.cs.drexel.edu:temp.txt
Command example:
scp temp.txt mjg88@tux.cs.drexel.edu:temp.txt
- Copying a file named temp.txt from your local Mac to your remote Tux home directory.
- You already navigated in the Terminal CLI on your Mac to the folder (directory) that you want to copy the file from.
Example 4
Command:
scp /Users/MacUserId/Desktop/temp.txt yourTuxUserid@tux.cs.drexel.edu:temp.txt
Command example:
scp /Users/mjg88/Desktop/temp.txt mjg88@tux.cs.drexel.edu:temp.txt
- Copying a file named temp.txt from your local Mac's Desktop folder to your remote Tux home directory.
Example 5
Command:
scp yourTuxUserid@tux.cs.drexel.edu:test.txt /Users/MacUserId/Desktop/
Command example:
scp mjg88@tux.cs.drexel.edu:test.txt /Users/mjg88/Desktop/
- Copy the file test.txt from the remote Tux host to your local Mac's Desktop folder
Example 6
Command:
scp /Users/MacUserId/Desktop/test.txt yourTuxUserid@tux.cs.drexel.edu:
Command example:
scp /Users/mjg88/Desktop/test.txt mjg88@tux.cs.drexel.edu:
- Copy the file "test.txt" from your local Mac's Desktop folder to the remote Tux host
Example 7
Command:
scp -r test_folder/ yourTuxUserid@tux.cs.drexel.edu:test_folder
Command example:
scp -r test_folder/ mjg88@tux.cs.drexel.edu:test_folder
- Copy the folder "test_folder" from your local Mac to the user's remote Tux host home directory
Example 8
Command:
Command example:
scp -r test_folder/ mjg88@tux.cs.drexel.edu:test-folder-newname
- Copy the folder "test_folder" from your local Mac to the user's remote Tux host home directory, and rename it as "test-folder-newname"
Example 9
Command:
scp -r "test folder"/ yourTuxUserid@tux.cs.drexel.edu:"test folder"
Command example:
scp -r "test folder"/ mjg88@tux.cs.drexel.edu:"test folder"
- Copy the folder "test folder" (space in the name) from your local Mac to the user's remote Tux host home directory
Example 10
Command:
scp -r "test folder"/ yourTuxUserid@tux.cs.drexel.edu:"test folder newname"
Command example:
scp -r "test folder"/ mjg88@tux.cs.drexel.edu:"test folder newname"
- Copy the folder "test folder" (space in the name) from your local Mac to the user's remote Tux host home directory, and rename it as "test folder newname"
SCP CLI Common Errors and Troubleshooting
- Mistyped or wrong file name or folder path
If you mistyped the file name or long folder path or directory path for the file or folder on Tux or your computer, the command will not work (or it will copy something else, or copy somewhere else. - Type in the following to find the full path name of whatever folder or directory you are in in Tux or in your Mac Terminal window.
pwd
Stands for print working directory. - If you type part of a file or folder name, and press the Tab key on your keyboard,
your computer will try to finish the rest of it.
If there are more than one folder or file that starts like that, it will only print some of the letters.
Type in 1 or more, and press Tab again.
You won't be able to do this for files on Tux. Open a different Terminal window, ssh into Tux there, and cd and use pwd to get the file name, then copy/paste. - /path/to/file/: No such file or directory
...or...
no could NOT resolve hostname c: Temporary failure in name resolution
...or...
usage: scp [-346ABCOpqRrsTv] [-c cipher] [-D sftp_server_path] [-F ssh_config] [-i identity_file]
[-J destination] [-l limit] [-o ssh_option] [-P port] [-S program] source ... target
You probably ssh'd into Tux BEFORE you scp'd in the same cmd.exe or PowerShell window.
Your computer would need to have a hostname and be a host or server on the internet for that to work,
and you'd have to specify userid@hostname:/path/to/file/fileORfolder2copy for your own computer, not Tux.
TL;DR?
If your command prompt says:
userid@tux#:~$
You ssh'd into tux.
Type in:
exit
Then try your scp command again. - Do NOT ssh into Tux BEFORE you scp.
In case the above troubleshooting tip still wasn't clear. :-) - scp: error: unexpected filename:
But no filename is listed.
Sometimes, the . command (used to mean "in the current folder) is listed as a file in a directory, and scp tries to copy it, but it's not a file. So you get this error. You can disregard this error.