SCP & SSH by Windows 10 PowerShell CLI 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+CLI+Command+Line+Interface+in+Windows+10+PowerShell/1_2f2krp68


SCP 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

Examples are in next section below. This section provides 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!


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


SCP PowerShell vs cmd.exe Tips

  • SCP (and SSH) can now be done in cmd.exe Command Prompt or Powershell.
  • But make sure OpenSSH client is installed in Windows.
    To verify, go to Start menu > Settings > Apps > optional features > scroll down and look for OpenSSH.
    This adds SSH functionality to Windows,
    and the user can use SSH from the Command Prompt (cmd.exe) or PowerShell.
  • PowerShell is recommended over cmd.exe, and Windows Terminal over either.
  • cmd.exe has different commands than li. (Use dir for ls.)
  • We no longer recommend running either as Administrator.
    scp and ssh work without Administrator access.
    And...
    You can't drag file icons into the cmd.exe or PowerShell window and get the full file path! ;-) ;-) ;-)


For SCP, Windows Terminal Works Too

  • Windows 11 users have Windows Terminal by default.
  • Windows 10 users can go to the Microsoft Store if they really want Windows Terminal.
  • Windows Terminal basically lets you use your choice of either cmd.exe or PowerShell or Linux commands.
  • The SCP commands covered here work for cmd.exe and PowerShell and Windows Terminal.


SCP Examples in cmd.exe/PowerShell/Windows Terminal

Below are example of how to use SCP. It's the same commands in PowerShell or Windows Terminal or cmd.exe (Windows command prompt).

For ALL of these examples:

  • Win10userID is your Windows 10 (or 11+) login userid.
  • "yourTuxUserid" is your Tux userid.
  • Do not use mjg88 as either your Tux or Windows 10 (or 11+) 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:test.txt "C: \Users\Win10userID\OneDrive - Drexel University\Desktop"\

Command example:
scp mjg88@tux.cs.drexel.edu:test.txt "C: \Users\mjg88\OneDrive - Drexel University\Desktop"\

  • Copying the test.txt file from your remote Tux home folder to your local Windows PC computer's desktop folder.
  • Quotes needed around the Desktop folder path on your computer because of the spaces in the OneDrive folder name.
  • Also, need a backslash or \ AFTER the end quote at the end of the file path to indicate it's a folder.
  • If you use \" , that escapes the quote and cmd.exe will think you need another line for the rest of the command. Press Ctrl + c to re-enter the command.


Example 2

Command:

scp yourTuxUserid@tux.cs.drexel.edu:test.txt .


Command example:
scp mjg88@tux.cs.drexel.edu:test.txt .

  • Copying a file named test.txt from your remote Tux home folder to your local Windows PC computer.
  • The period at the end indicates that the file will be copied to the current directory or folder you are in within cmd.exe or PowerShell.


Example 3

Command:

scp test.txt yourTuxUserid@tux.cs.drexel.edu:test.txt

Command example:

scp test.txt mjg88@tux.cs.drexel.edu:test.txt

  • Copying a file named test.txt from your local Windows PC to your remote Tux home directory.
  • You already navigated in cmd.exe or PowerShell to the folder (directory) on your local Windows PC that you want to copy the file from.

Example 4

Command:

scp C:\Users\Win10userID\Downloads\test.txt yourTuxUserid@tux.cs.drexel.edu:test.txt

Command example:

scp C:\Users\mjg88\Downloads\test.txt mjg88@tux.cs.drexel.edu:test.txt

  • Copying a file named test.txt from your local Windows PC's Downloads folder to your remote Tux home directory.


Example 5

Command:

scp yourTuxUserid@tux.cs.drexel.edu:test.txt C:\Users\Win10userID\Downloads\

Command example:

scp mjg88@tux.cs.drexel.edu:test.txt C:\Users\mjg88\Downloads\

  • Copy the file test.txt from the remote Tux host to your local Windows PC's Download folder


Example 6

Command:

scp C:\Users\Win10userID\Downloads\test.txt yourTuxUserid@tux.cs.drexel.edu:

Command example:

scp C:\Users\mjg88\Downloads\test.txt mjg88@tux.cs.drexel.edu:

  • Copy the file "test.txt" from your local Windows PC's Desktop folder to the remote Tux host
  • Note: If you forget the colon or : at the end, you will just create a file named "yourTuxUserid@tux.cs.drexel.edu" or "mjg88@tux.cs.drexel.edu" in whatever folder or directory you type this command in the cmd.exe or PowerShell.


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" (with a file inside) from your local Windows PC to the user's remote Tux host home directory


Example 8

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" from your local Windows PC to the your remote Tux host home directory, and rename it as "test-folder-newname".


Example 9

Command:

scp -r "C:\Users\Win10userID\Downloads\test folder"\ yourTuxUserid@tux.cs.drexel.edu:/home/yourTuxUserid/

Command example:

scp -r "C:\Users\mjg88\Downloads\test folder"\ mjg88@tux.cs.drexel.edu:/home/mjg88/

  • Copy the folder "test folder" (space in the name) from your local Windows PC to your remote Tux host home directory.
  • Also, need a backslash or \ AFTER the end quote at the end of the file path to indicate it's a folder.
  • If you use \" , that escapes the quote and cmd.exe will think you need another line for the rest of the command. Press Ctrl + c to re-enter the command.


Example 10

Command:
scp .\test_folder\test.txt yourTuxUserid@tux.cs.drexel.edu:


Command example:

scp .\test_folder\test.txt mjg88@tux.cs.drexel.edu:

  • Copy the file "text.txt" within the sub-folder or sub-directory "test_folder" from your local Windows PC to your remote Tux host home directory.
  • This copies only that file. Not the entire sub-folder or sub-directory.
  • We're not renaming the file. And we're placing it at the top of level of your remote Tux host home directory. So no need to specify a folder or sub folder or file name nor a path to a file, folder, or directory.


Example 11

Command:

scp test.txt yourTuxUserid@tux.cs.drexel.edu:test-folder2\

Command example:
scp test.txt mjg88@tux.cs.drexel.edu:test-folder2\

  • Copy the file "test.txt" from your local Windows PC to the sub-folder or sub-directory "test-folder2" to your remote Tux host home directory.


Example 12

The screenshot below shows a few examples where spaces are in the folder name and/or file name,
and how to write the scp command accordingly when that occurs.

  • You need a backslash or \ AFTER the end quote at the end of the file path to indicate it's a folder.
  • If you use \" , that escapes the quote and cmd.exe will think you need another line for the rest of the command. Press Ctrl + c to re-enter the command.

Select Administrator Command Prompt scp space in file name and folder name


SCP CLI Tips on Windows

To use SCP Command Line Interface (CLI) on a Windows device:

  1. Search 'cmd' in the bottom left search bar.
    Select 'Command Prompt'.
    Do NOT click on 'Run as administrator' unless you have a reason to.
  2. In the cmd, you can change folders or directories by typing 'cd', followed by the folder name or folder-file path, and then click on the 'Enter' or 'Return' key.
    Example 1: cd folder_name
    Example 2: cd system32
    Also, note:
    Use 'cd ../' or 'cd ..' to go up 1 folder level or 1 directory level.
    Use 'cd ../..' to go up 2 folder levels or 2 directory levels.
    2 example screenshots below.
    Administrator Command Prompt CD and dots example 1

    Administrator Command Prompt CD and dots example 2

  3. Use 'dir' to displays a list of a directory's files and subdirectories.
    The command displays the disk's volume label and serial number,
    followed by a list of directories and files on the disk
    (including filenames, date, and last modified).
    See example screenshots ABOVE and BELOW.

  4. Use 'cd Desktop' to change the directory to the computer's Desktop directory.cmd exe cd alone is pwd - 2 periods slash - dir is ls - empty Desktop with OneDrive

  5. When moving files/folders, do NOT use 'mv'.
    Use 'move {filename you want to move} '{Desired location to put the file}'
    cmd exe move command example

  6. Want a quick way of getting a long and complicated file path (or folder path, or file name)?
    Open up File Explorer.
    Double-click through folders to navigate to the file or folder.
    Drag the file or folder icon from the File Explorer window to the cmd.exe or PowerShell window.
    The full file path or folder path should appear in the command prompt line.
    Use Home or End buttons to navigate to the start or end of the line.
    Typing over characters? Press Insert or Ins to get out of overwrite mode.
    Do NOT run as Administrator. Or this will not work.
    See https://youtu.be/prVHU1fLR20?t=198

  7. You can easily open cmd.exe or PowerShell in the same folder that you are viewing in File Explorer.
    Just type cmd or powershell in the folder path or address line in file explorer.
    And press the Enter or Return key.
    See
    https://youtu.be/prVHU1fLR20?t=186

  8. Or look at your command prompt, or type in cd at your command prompt.
    You'll get a line showing your current working folder or directory, similar to pwd in linux.

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



SCP CLI Common Errors and Troubleshooting

  1. Mistyped or wrong file name or folder path
    See #6 & #7 tips above for how to avoid this, but 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.
  2. /path/to/file/: No such file or directory
    ...or...
    ssh 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.
  3. Do NOT ssh into Tux BEFORE you scp.
    In case the above troubleshooting tip still wasn't clear. :-)
  4. 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.