Network Services and Security · Topic 2 of 7
SFTP and SCP
Back up and restore Cisco configurations and IOS images with SCP and SFTP over SSH, enable the SCP server, and see why TFTP and FTP are not secure.
- 5 min
- SCP and SFTP run over SSH on TCP port 22 and are encrypted.
- TFTP (UDP 69) and FTP (TCP 21) are insecure and are not the secure answer.
- The device needs SSH working: a domain name, RSA keys and
ip ssh version 2.
What it is
SCP and SFTP copy files over an SSH session, so the login, the file and the commands are encrypted.
Engineers use them to back up a configuration, restore it, or load a new software image. Both use TCP port 22, the same port as SSH, so a firewall that allows SSH usually allows them.
SCP (Secure Copy) copies a file in one command, like cp over the network. SFTP (SSH File Transfer Protocol) is a file transfer protocol that runs inside SSH and can also list and manage remote files.
For contrast, TFTP (UDP port 69) has no login and no encryption. FTP (TCP ports 21 and 20) sends its username and password in clear text. Neither is secure, and the v2.0 exam expects you to choose SCP or SFTP.
How it works
The Cisco copy command names a source and then a destination. A URL-style prefix selects the protocol.
Prerequisites
SCP and SFTP ride on SSH, so SSH must work first.
hostname R1
ip domain name example.com
username admin privilege 15 secret STRONGPASS
crypto key generate rsa modulus 2048
ip ssh version 2
SCP server on the device
To let others copy files to or from the router with SCP, enable the SCP server. It also needs AAA, because the device authorizes the SCP session as an exec session.
aaa new-model
aaa authentication login default local
aaa authorization exec default local
ip scp server enable
Without AAA authorization, a remote scp to the router is refused even when SSH works. Check this first when SCP fails.
Copy commands on the device
The device acts as the client when you give a remote URL.
R1# copy running-config scp://[email protected]/R1-config.txt
R1# copy scp://[email protected]/R1-config.txt flash:
R1# copy flash:isr-image.bin scp://[email protected]/isr-image.bin
R1# copy sftp://[email protected]/R1-config.txt flash:
The prefix is scp: or sftp:, followed by the user and server address. If you omit parts of the URL, the device prompts for the address or name of the remote host, the username, the source or destination file name, and then the password.
Direction always follows copy SOURCE DESTINATION. copy running-config scp:... sends the configuration out. copy scp:... flash: brings a file in.
Configuration and image backups
| Task | Command idea |
|---|---|
| Back up the active config | copy running-config scp: |
| Back up the saved config | copy startup-config scp: |
| Restore a config | copy scp: startup-config then reload |
| Save a software image | copy flash: scp: |
| Load a software image | copy scp: flash: |
Copying a file into running-config merges it with the active configuration. Copying into startup-config replaces the saved one, and it takes effect at the next reload.
Checking before and after
R1# dir flash:
R1# show file systems
R1# verify /md5 flash:isr-image.bin
R1# show ip ssh
dir flash: and show file systems confirm there is free space before you copy an image. verify /md5 calculates the hash of the file so you can compare it with the value the vendor publishes. A corrupted image can stop a device booting. show ip ssh confirms that SSH, and therefore SCP and SFTP, is available.
A secure copy that hangs usually has an SSH problem, not a file problem. Prove SSH from the same source first.
Reading a failure
| Symptom | Likely cause |
|---|---|
| Connection times out | No route, wrong server address, or a firewall or ACL blocking TCP 22 |
| Permission denied | Wrong username or password, or the account lacks rights on the server |
| Works from a PC but not to the router | ip scp server enable or AAA authorization missing |
| Copy starts then fails | Not enough free flash space, or the file name or path is wrong |
Common mistakes
Using TFTP or FTP because it is quicker. Both send data unprotected. SCP and SFTP are the secure choices.
Forgetting ip scp server enable. It is needed only when the router is the SCP server, not when it copies out.
Skipping the SSH prerequisites. A missing domain name or RSA keys means no SSH, and therefore no secure copy.
Reversing source and destination. Overwriting the running configuration with an old file is easy to do.
Not verifying an image. Always compare the hash before you install it.
Assuming a merge is a replace. Copying to running-config adds to what is there. Commands you wanted removed stay.
What to remember for the exam
- SCP and SFTP run over SSH on TCP port 22 and are encrypted.
- TFTP (UDP 69) and FTP (TCP 21) are insecure and are not the secure answer.
- The device needs SSH working: a domain name, RSA keys and
ip ssh version 2. ip scp server enableturns the router into an SCP server, and AAA authentication and authorization must be set.copy SOURCE DESTINATION:copy running-config scp:sends the config out.- Copying into
running-configmerges. Copying intostartup-configreplaces. verify /md5checks an image against the published hash.dir flash:shows free space before a transfer.
Check yourself
Which command lets a router accept SCP transfers, and what else must be configured?
ip scp server enable. SSH must work and AAA authentication and authorization must be configured.What is the difference between copying a file to
running-configand tostartup-config?Copying to
running-configmerges the file with the active configuration. Copying tostartup-configreplaces the saved configuration.Why choose SCP or SFTP over TFTP or FTP?
SCP and SFTP run over SSH on TCP 22 and encrypt the login and the data. TFTP has no authentication or encryption, and FTP sends its login in clear text.
Topic 2 of 7 in Network Services and Security
Test yourself on Network Services and Security
The full Cisco CCNA 200-301 v2.0 question bank has 1,242 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Cisco. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.