08-SSH Configuration
08-SSH Configuration
Contents
1 Configuring SSH................................................................................................................................1
1.1 Introduction................................................................................................................................1
1.1.1 Overview........................................................................................................................1
1.1.2 Principles.......................................................................................................................1
1.3.1 Overview........................................................................................................................4
1.3.6 Configuring the Key and Key Exchange Algorithm of the SSH Server.........................6
1.4.1 Overview........................................................................................................................9
1.4.3 Procedure......................................................................................................................9
i
Configuration Guide Contents
1.5.1 Overview......................................................................................................................10
1.6.1 Overview......................................................................................................................11
1.6.2 Procedure....................................................................................................................11
1.7 Monitoring................................................................................................................................12
ii
Configuration Guide Configuring SSH
1 Configuring SSH
1.1 Introduction
1.1.1 Overview
Secure Shell (SSH) is a network security protocol that requires encryption and authentication and is used for
remote access and file transfer.
SSH is based on the server/client structure. The device supports both the SSH server and client functions. As
an SSH server, the device can connect to multiple SSH clients. As an SSH client, the device allows users to
establish SSH connections with devices that support the SSH server function.
The SSH function is similar to the Telnet service. However, the encryption and authentication features of SSH
can ensure stronger security guarantee for users. When users log in to the device through an insecure network
environment, SSH can effectively protect the device against attacks, such as IP address spoofing and plaintext
password interception.
1.1.2 Principles
1. SSH Version
SSHv1 and SSHv2 are available, and the two are mutually exclusive. Compared with SSHv1, SSHv2 provides
higher performance and security.
The device supports both versions and supports SSH interaction using the IPv4 and IPv6 addresses. Unless
otherwise specified, SSH in this document refers to SSHv2.
Interaction between an SSH client and an SSH server is classified into seven phases: connection
establishment, version negotiation, key exchange and algorithm negotiation, user authentication, session
request, session interaction, and session closure.
Connection establishment
aThe server listens on Transmission Control Protocol (TCP) port 22 and waits for a connection request from the client.
bThe client initiates a TCP connection request to port 22 of the server to establish a TCP connection with the server.
Version negotiation
dThe client receives and processes the packet and replies the version to be used to the server.
eThe server processes the reply from the client and determines whether version negotiation is successful.
If the version negotiation succeeds, key exchange and algorithm negotiation are performed.
fThe server and the client exchange the algorithm negotiation packet with each other and determine the
final algorithm based on their capacity.
1
Configuration Guide Configuring SSH
gThe server and the client work together to generate a session key and session ID according to the key exchange
algorithm and host key, which will be applied to subsequent user authentication, data encryption, and data
decryption.
User authentication
iThe server repeatedly conducts authentication for the client until the authentication succeeds or the server shuts down
the connection because the maximum number of authentication attempts is reached.
Session request
jAfter the authentication is successful, the client sends a session request to the server.
kThe server waits and processes the client's session request. After the session request is successfully
processed, the SSH client and server enter the session interaction phase.
Session interaction
In this phase, bidirectional transmission and processing of encrypted data are allowed.
nThe server encrypts and sends the processing result to the client.
oThe client decrypts and processes the message from the server.
Session closure
The server and client disconnect the connection, and close the session.
SSH supports password authentication, public key authentication, and other client authentication mechanisms.
Password authentication
aThe client sends encrypted username and password to the server to request password authentication.
bAfter receiving the request, the server decrypts the information, authenticates the client's identity through the
Authentication, Authorization and Accounting (AAA) service (including local authentication and remote
authentication), and sends an authentication success or failure message to the client.
Public key authentication uses digital signature algorithms, such as Rivest-Shamir-Adleman (RSA) and
Digital Signature Algorithm (DSA) to authenticate a client.
cThe client sends a public key authentication request to the server. This request contains information,
including the username, public key, and public key algorithm.
dAfter receiving the request, the server checks whether the public key is valid.
eIf not, the server directly returns an authentication failure message. If yes, the server performs digital signature
authentication on the client and returns a message indicating successful or failed authentication.
2
Configuration Guide Configuring SSH
A public key algorithm is an asymmetric encryption algorithm used to encrypt communication data between an
SSH client and server to ensure data transfer security.
The device supports three public key algorithms: RSA, DSA, and Elliptic Curves Cryptography (ECC).
RSA
RSA is based on most factorization algorithms and can be used for key and signature exchange. Due to
low encryption and decryption efficiency, it does not apply to encryption and decryption of a large number of
data.
DSA
Compared with RSA, DSA can be used only for signature and cannot be used for data encryption and
decryption or key exchange. However, its efficiency is much higher than that of RSA.
ECC
ECC is based on the discrete logarithm algorithm and is difficult to be cracked down. In same security
conditions, ECC has higher processing efficiency and lower storage and bandwidth requirements than RSA
and DSA.
RFC 4419: Diffie-Hellman Group Exchange for the Secure Shell (SSH) Transport Layer Protocol
RFC 4716: The Secure Shell (SSH) Public Key File Format
RFC 3526: More Modular Exponential (MODP) Diffie-Hellman groups for Internet Key Exchange (IKE)
3
Configuration Guide Configuring SSH
(Optional) Configuring the Key and Key Exchange Algorithm of the SSH Server
After the SSH server function is configured on a device, SSH clients can remotely log in to the device.
(Optional) Configuring the Key and Key Exchange Algorithm of the SSH Server
enable
configure terminal
4
Configuration Guide Configuring SSH
1. Overview
The SSH server supports the SSHv1 and SSHv2 versions. Compared with SSHv1, SSHv2 has higher
performance and security. During actual configuration, select a proper SSH server version based on the client
version and security requirements.
3. Procedure
(1)Enter the privileged EXEC mode.
enable
configure terminal
The SSH server is compatible with the SSHv1 and SSHv2 clients by default.
1. Overview
An SSH server uses port 22 to listen to client connections by default. The listening port can be changed through
configuration.
Port 22 is a protocol-defined standard port and vulnerable to attacks from malicious users. If an attacker
accesses this port frequently in a short time, problems such as bandwidth waste and performance deterioration
may occur. As a result, other users cannot access the server (that is, the DoS attack). Changing the listening
port can effectively prevent the problems.
2. Procedure
(1)Enter the privileged EXEC mode.
enable
configure terminal
5
Configuration Guide Configuring SSH
1.3.6 Configuring the Key and Key Exchange Algorithm of the SSH Server
1. Overview
The key and key exchange algorithm of the SSH server are configured to establish a communication connection
between the client and server.
3. Procedure
(1)Enter the privileged EXEC mode.
enable
configure terminal
If no key is generated on the SSH server, this parameter must be configured. To delete the public key of the
SSH server, run the crypto key zeroize { dsa | ecc | rsa } command instead of the no form of this
command.
enable
configure terminal
The encryption modes supported by the SSH server are ctr and gcm by default.
It is approved that cbc and others encryption algorithms can be decrypted in a limited period of time.
Therefore, organizations or companies that have high security requirements can set the encryption modes
supported by the SSH server to ctr and gcm to enhance the security level of the SSH server.
6
Configuration Guide Configuring SSH
SSHv1 servers do not support any message authentication algorithms, and SSHv2 servers support the
MD5, SHA1, SHA1-96, MD5-96, sha2-256, and sha2-512 message authentication algorithms by default.
1. Overview
Parameters related to user authentication include the authentication timeout time, number of authentication
attempts, and public key authentication.
2. Procedure
(1)Enter the privileged EXEC mode.
enable
configure terminal
The default user authentication timeout time on the SSH server is 120 seconds.
If authentication still does not succeed when the user authentication timeout time expires, user
authentication fails.
The default maximum number of authentication attempts allowed on the SSH server is 3.
If the number of authentication attempts of a user by using the account and password exceeds the
configured number of authentication attempts, user authentication fails.
If a client needs to use public key authentication, the client's public key and username need to be
associated with the device. Only SSHv2 supports public key authentication.
1. Overview
An ACL can filter out users who meet specific rules. This prevents unauthorized users from accessing the
device through SSH and causing security risks.
2. Procedure
(1)Enter the privileged EXEC mode.
enable
configure terminal
(IPv4 address)
7
Configuration Guide Configuring SSH
(IPv6 address)
1. Overview
When the number of authentication failures for login through SSH reaches the configured limit in an
authentication failure count period, the source IP address is blocked. That is, the SSH client that uses this
source IP address is not allowed to log in to the device to prevent the device being attacked. The SSH client
can log in to the device only after the IP address is awakened. This function is enabled by default and can be
manually disabled.
2. Procedure
(1)Enter the privileged EXEC mode.
enable
configure terminal
(4)(Optional) Configure the number of authentication failures for blocking an IP address and the time period for counting
authentication failures on the SSH server.
The allowed maximum number of authentication failures is 6, and the time period for counting
authentication failures is 5 minutes by default.
(5)(Optional) Configure the time period for awakening blocked IP addresses on the SSH server.
After the time period for awakening blocked IP addresses is reached, SSH clients using these IP addresses
can log in to the SSH server again.
(6)(Optional) Clear user information with blocked IP addresses and authentication failures.
After the user information is cleared, corresponding clients can log in to the SSH server again.
enable
8
Configuration Guide Configuring SSH
Serving as an SSH server, the device may connect to multiple SSH clients. You can run this command to
forcibly disconnect a client from the device. The client disconnection methods are as follows:
Specify an SSH session ID. To display the SSH session ID of a client, run the show ssh command.
Specify a Virtual Teletype (VTY) session ID. To display the VTY session ID of a client, run the show
users command. This command can be used to disconnect SSH connections only.
Secure copy protocol (SCP) is a protocol that supports network file transfer. SCP is implemented based on
RCP. RCP is responsible for file transfer, and SSH provides the authentication and encryption functions for
RCP.
After the SCP server function is configured on the device, users can run the scp command to upload files to or
download files from the device. Data exchanged during the process is encrypted for security.
The SSH server function must be enabled before the SCP server function is configured.
1.4.3 Procedure
enable
configure terminal
(4)(Optional) Configure the transmission path for uploading files to or downloading files from the SCP server.
The default transmission path for file upload and download is flash:/.
When the local device is configured as an SSH client, the device can establish an SSH connection to another
device that provides the SSH server service to remotely log in to the device for management operations.
9
Configuration Guide Configuring SSH
enable
(2)Establish a remote encrypted session with the SSH server as an SSH client.
SSHv1 supports only the DES (56-bit key) and 3DES (168-bit key) encryption algorithms. SSHv2 supports
the following Advanced Encryption Standards (AES): ASE128-CBC, AES192-CBC, AES256-CBC, AES128-
CTR, AES192-CTR, and AES256-CTR. If you specify an unmatched encryption or authentication algorithm
when selecting an SSH version, the unmatched algorithm will be ignored when a connection is established.
configure terminal
After the source interface is configured, the SSH client uses the IP address on this interface as the global
source address during communication. If no source interface is configured, the source address of SSH
packets will be obtained by querying the corresponding route based on the destination address. If no
source interface or source IP address is independently specified for an SSH connection, the global
configuration is used.
1. Overview
After the device establishes an SSH session with the SSH server as a client, you can press Ctrl+Shift+6+X to
exit the session temporarily. After exiting the session, you can run the corresponding command to restore the
session.
3. Procedure
(1)Enter the privileged EXEC mode.
enable
10
Configuration Guide Configuring SSH
ssh-session session-id
1. Overview
After the device connects to the SSH server as an SSH client, you can run the corresponding command to
disconnect an SSH session with the specified session ID.
2. Procedure
(1)Enter the privileged EXEC mode.
enable
You can run the show ssh-session command to display session-id of the device.
When the local device is configured as an SCP client, the device can run the scp command to upload files to or
download files from a device that provides the SCP server service. Data exchanged during the process is
encrypted for security.
1.6.2 Procedure
enable
configure terminal
After the source interface is configured, the SCP client uses the IP address on the interface as the global
source address during communication. If no source interface is configured, the source address of SCP
packets will be obtained by querying the corresponding route based on the destination address. If no
source interface or source IP address is independently specified for an SCP connection, the global
configuration is used.
(4)Upload files to or download files from the remote SCP server as an SCP client.
11
Configuration Guide Configuring SSH
1.7 Monitoring
Run the show commands to check the running status of a configured function to verify the configuration effect.
System resources are occupied when debugging information is output. Therefore, disable the debugging
function immediately after use.
Table 1-1Monitoring
Command Purpose
1. Requirements
After the SSH server function is enabled on a device, users can use the password configured in line
configuration mode to log in to the device.
2. Topology
G0/1
Host 192.168.1.1 Device
12
Configuration Guide Configuring SSH
3. Notes
4. Procedure
Device> enable
Device# configure terminal
Device(config)# enable service ssh-server
(2)Set the line password to password1.
Device(config-line)# login
5. Verification
Use the client software to log in to the device through SSH. The password is password1, and the
username can be any value. Verify that the login is successful. Use the PuTTY software as an example.
The login page is as follows:
13
Configuration Guide Configuring SSH
Device#show users
Line User Host(s) Idle Location
---------------- ------------ -------------------- ----------
------------------
0 con 0 --- idle 00:00:16 ---
* 1 vty 0 --- idle 00:00:00 192.168.1.2
6. Configuration Files
!
enable service ssh-server
!
line console 0
line vty 0 4
login
password 7 $10$396$mnO2p3SVaxm7$
!
1. Requirements
After the SSH server function is enabled on a device, users can use the local account created on the device to
log in to the device through SSH.
2. Topology
G0/1
Host 192.168.1.1 Device
3. Notes
4. Procedure
Device> enable
Device# configure terminal
Device(config)# enable service ssh-server
(2)Add a local user whose username is hostname1 and password is password1.
14
Configuration Guide Configuring SSH
5. Verification
Use the client software to log in to the device through SSH. The username is hostname1, and the
password is password1. Verify that the login is successful. Use the PuTTY software as an example. The
login page is as follows:
Device#show users
Line User Host(s) Idle Location
---------------- ------------ -------------------- ----------
------------------
0 con 0 --- idle 00:00:16 ---
* 1 vty 0 hostname1 idle 00:00:00 192.168.1.2
6. Configuration Files
!
username hostname1 password 7 $10$2fe$Rd/C4ijEl+UN$
15
Configuration Guide Configuring SSH
!
enable service ssh-server
!
line console 0
line vty 0 4
login local
!
1. Requirements
2. Topology
G0/1
Host 192.168.1.1 Device AAA server
3. Notes
Configure the AAA server and add an AAA user on the AAA server.
Enable the AAA service on the device and set the SSH authentication method to AAA server.
4. Procedure
(1)Configure the AAA server and add an AAA user whose username is hostname1 and password is password1 on the
AAA server. (For details about AAA server configuration, see the AAA server configuration guide.)
Device> enable
Device# configure terminal
Device(config)# enable service ssh-server
(3)Enable AAA services.
16
Configuration Guide Configuring SSH
5. Verification
Use the client software to log in to the device through SSH. The username is hostname1, and the
password is password1. Verify that the login is successful. Use the PuTTY software as an example. The
login page is as follows:
Device#show users
Line User Host(s) Idle Location
---------------- ------------ -------------------- ----------
------------------
0 con 0 --- idle 00:00:16 ---
* 1 vty 0 hostname1 idle 00:00:00 192.168.1.2
6. Configuration Files
!
aaa new-model
aaa authentication login login-method group radius local
!
17
Configuration Guide Configuring SSH
1. Requirements
When the device serves as the SSH server, users can use public key authentication to log in to the device
without needing a password.
2. Topology
G0/1
Host 192.168.1.1 Device
3. Notes
Use the client software to generate a pair of keys (public key and private key).
Copy the public key file to the flash memory of the device and associate the key with the user.
4. Procedure
(1)Configure a local user and enable local user authentication in a line. For details, see 1.8.2 Configuring Local User
Authentication for SSH Clients.
(2)Use the client software to generate a pair of keys. The Ubuntu environment is used as an example. The generated
private key is id_rsa and public key is id_rsa.pub.
root@ubuntu:~# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:6a/sWJjpx97QQEs9Aoiph5Ry452ybIyNyZUsT48Irrw root@ubuntu
The key's randomart image is:
+---[RSA 2048]----+
| .o .. |
|.o= . . . |
|o=.o.. + o |
|+.+=o o + . |
|+O*oo S |
|++*o . = o |
|o. +.+ . |
18
Configuration Guide Configuring SSH
|.. . +o+ |
| E. o+=.o |
+----[SHA256]-----+
(3)Copy the public key file to the flash memory of the device (omitted).
Device> enable
Device# configure terminal
Device(config)# ip ssh peer hostname1 public-key rsa flash:test_key.pub
5. Verification
Verify that users can log in to the device through public key authentication. (The Ubuntu environment is used as
an example.)
root@ubuntu:~/.ssh# ls
id_rsa id_rsa.pub
root@ubuntu:~/.ssh# ssh -i id_rsa [email protected]
6. Configuration Files
!
username hostname1 password 7 $10$2fe$Rd/C4ijEl+UN$
!
ip ssh peer hostname1 public-key rsa flash:id_rsa.pub
!
enable service ssh-server
!
line console 0
line vty 0 4
login local
!
1. Requirements
When the device serves as the SCP server, users can run the scp command to upload files to and download
files from the device.
2. Topology
G0/1
Host 192.168.1.1 Device
19
Configuration Guide Configuring SSH
3. Notes
4. Procedure
(1)Configure a local user and enable local user authentication in a line. For details, see 1.8.2 Configuring Local User
Authentication for SSH Clients.
Device> enable
Device# configure terminal
Device(config)# enable service ssh-server
(3)Enable the SCP server function.
5. Verification
Verify that the client can run the scp command to upload files to the device. The Ubuntu environment is used as
an example here.
(1)In the Ubuntu shell environment, run the scp command to upload file.txt to the device.
Device> enable
Device# dir flash:file.txt
Number Properties Size Time Name
------ ---------- ---------- ------------------------ --------------------
1 -rwx 14B Fri Apr 2 10:00:00 2021 file.txt
Verify that the client can run the scp command to download files from the device. The Ubuntu environment is
used as an example here.
(1) The file.txt file exists in the flash directory of the device.
Device> enable
Device# dir flash:file.txt
Number Properties Size Time Name
------ ---------- ---------- ------------------------ --------------------
1 -rwx 14B Fri Apr 2 10:00:00 2021 file.txt
(3)In the Ubuntu shell environment, run the scp command to download file.txt from the device and rename it as
file1.txt.
20
Configuration Guide Configuring SSH
root@ubuntu:~# ls -l file1.txt
-rwxr--r-- 1 root root 14 Apr 2 10:00 file1.txt
6. Configuration Files
!
username hostname1 password 7 $10$2fe$Rd/C4ijEl+UN$
!
enable service ssh-server
!
ip scp server enable
!
line console 0
line vty 0 4
login local
!
1. Requirements
When the device serves as an SSH client, the device can log in to the SSH server through SSH.
2. Topology
G0/1 192.168.1.2
192.168.1.1
Device SSH server
3. Notes
4. Procedure
(1)Configure a valid user on the SSH server. (For details, see the SSH server user manual.)
Device> enable
Device# ssh -l admin 192.168.1.2
5. Verification
21
Configuration Guide Configuring SSH
1. Requirements
When the device serves as an SCP client, the device can run the scp command to upload files to and download
files from the SCP server.
2. Topology
G0/1 192.168.1.2
192.168.1.1
Device SCP server
3. Notes
Run the scp command to upload files to or download files from the SCP server.
4. Procedure
(1)Configure a valid user on the SCP server. For details, see the SCP server user manual.
(2)Run the scp command to copy file.txt from the SCP server to the flash memory of the device.
Device> enable
Device# scp [email protected]:/file.txt flash:/file.txt
(3)Run the scp command to copy local file file.txt from the device to the SCP server.
Device> enable
Device# scp [email protected]:/file.txt flash:/file.txt
5. Verification
Verify that the file on the SCP server is successfully copied to a local directory.
Device> enable
Device# scp oob flash:/file.txt [email protected]:/file.txt
Device> enable
Device# scp [email protected]:/file.txt flash:/file.txt
22
Configuration Guide Configuring SSH
%Trying 192.168.1.2,...open
[email protected]'s password:
Press Ctrl+C to quit
!
Transmission success.
23