Cisco switches generate RSA key pairs natively through the crypto key generate rsa command, and a 2048-bit modulus with public exponent 65537 is the recommended starting size for SSH server identities, HTTPS certificate signing, and IPsec tunnel authentication. The switch stores the key material inside its private configuration and uses it to negotiate encrypted sessions with management hosts. When you instead need an RSA key pair offline — for a companion system, for classroom demonstration, or for a workflow that demands browser-generated PEM output — the RSA Key Generator produces the same underlying 2048- or 3072-bit RSA key material entirely in your browser using the platform Web Cryptography API. No key bytes are transmitted to any application server. The public half is exported as SubjectPublicKeyInfo PEM and the private half as unencrypted PKCS#8 PEM, both of which are standard ASN.1 envelopes defined in RFC 7468. This guide walks through both paths — the on-switch crypto key generate rsa workflow and the offline browser workflow — so you can pick the approach that matches your deployment.

how to generate rsa key cisco switch
how to generate rsa key cisco switch

Cisco Switch RSA Key Generation Methods

Two practical paths exist for producing an RSA key pair in a Cisco environment. The first is to let the switch generate its own key, which is the default approach for SSH server identities on IOS and Nexus devices. The second is to generate the key offline on a workstation and then import the public component onto the switch or a peer system. Both approaches rely on the same RSA mathematics defined in RFC 8017, but they differ in where the private key physically lives and how it is protected.

On-switch generation is the simplest path when the switch itself will act as the SSH server or the HTTPS endpoint. The private key never leaves the device, the running configuration holds it, and copy running-config startup-config persists it across reloads. Offline generation with a browser tool is the right path when you need a key pair for a system that will connect to the switch, when you want to inspect or distribute the PEM blocks, or when the switch does not support the key size or label your protocol requires. Offline generation also gives you the public and private envelopes in copy-pasteable form, which is useful for automation, documentation, and protocol testing.

Cisco IOS Commands for RSA Key Generation

Cisco IOS and IOS-XE devices expose RSA key generation through a small, well-defined command sequence. The steps below work on Catalyst switches running IOS or IOS-XE and on most ISR routers. Nexus switches running NX-OS use a slightly different syntax shown immediately after.

  1. Connect to the switch via console, Telnet, or SSH and enter privileged EXEC mode with enable, supplying the enable password when prompted.
  2. Enter global configuration mode with configure terminal. Before generating an RSA key, confirm the device has a hostname and domain name, because IOS uses them to label the key: hostname CORE-SW1 and ip domain-name example.lan.
  3. Generate the key pair with crypto key generate rsa general-keys modulus 2048. IOS will prompt for confirmation because regenerating overwrites the existing key. The modulus value is the bit length, and 2048 is the broadly interoperable default.
  4. Optional: add a usage label with crypto key generate rsa general-keys label SSH-KEY modulus 2048 exportable if you plan to export the public key later or if multiple keys must coexist.
  5. Exit configuration mode with end, then verify the key with show crypto key mypubkey rsa. The output reports the modulus length, the key label, and the fingerprint hash.
  6. Save the configuration with copy running-config startup-config so the key survives a reload. Without this step the key is lost on reboot.

On Cisco Nexus switches running NX-OS, the equivalent sequence is configure terminal, ssh key rsa 2048, exit, show ssh key, and copy running-config startup-config. The Nexus command set does not expose every IOS option, but a 2048-bit RSA key with exponent 65537 is generated in both families.

Generate RSA Keys in Your Browser with RSA Key Generator

When the workflow calls for PEM output — for a script that pushes the public key to a configuration file, for a tool that expects SPKI input, or for a classroom demonstration — the RSA Key Generator produces a fresh key pair inside your browser. The implementation calls the platform Web Cryptography API, which generates two large primes and assembles them into an RSA-OAEP key with SHA-256 and exponent 65537. No network request carries key material.

  1. Confirm the consuming application expects RSA-OAEP with SHA-256, exponent 65537, and either SPKI public PEM or PKCS#8 private PEM. Mismatched parameters — for example SHA-1 or PKCS#1 v1.5 — will cause the key to import but silently fail at runtime.
  2. Open the RSA Key Generator, choose 2048 or 3072 bits, and click generate. A 3072-bit modulus takes noticeably longer because the browser must find two larger primes; allow extra time and do not interrupt the tab.
  3. Copy the public PEM block that begins with BEGIN PUBLIC KEY and distribute it only to systems that need to encrypt for the holder. The block is a Base64-wrapped ASN.1 SubjectPublicKeyInfo structure as specified in RFC 7468.
  4. Move the private PEM block that begins with BEGIN PRIVATE KEY directly into a protected keystore, hardware security module, or encrypted secret manager. It is not password-encrypted, and anyone who obtains it can decrypt compatible ciphertext.
  5. Run a protocol-level round trip: import the public key into the target system, encrypt a known UTF-8 message, and assert exact recovery after decryption with the private key. A successful import alone is not sufficient evidence of parameter agreement.

RSA Key Parameters: 2048 vs 3072 Bits

Modulus length is the most visible knob on any RSA workflow. The table below compares the two sizes the RSA Key Generator exposes, using the tradeoffs described in RFC 8017 and the practical behavior of browser Web Crypto implementations.

Property 2048-bit modulus 3072-bit modulus
Interoperability Broadly supported across SSH, TLS, and IPsec implementations Supported by modern implementations; some legacy peers may refuse
Generation time in browser Short — typically under a second on a modern laptop Noticeably longer — two larger primes must be found
Operational cost Faster encryption and decryption operations Slower per-operation cost across the lifetime of the key
Security margin against factoring Acceptable through the late 2020s for most threat models Larger margin with higher cost — preferred for long-lived identities
Cisco IOS default behavior Matches the standard crypto key generate rsa modulus 2048 usage Available on most modern IOS-XE images; verify with show crypto key mypubkey rsa

The single worked example below illustrates the size relationship. A 2048-bit modulus is 256 bytes, so a maximum RSA-OAEP plaintext payload with SHA-256 padding is roughly 190 bytes after subtracting encoding overhead. A 3072-bit modulus is 384 bytes and accepts proportionally larger payloads. Applications that need to protect files or long messages therefore encrypt a random symmetric key with RSA-OAEP and encrypt the bulk data with authenticated symmetric encryption; the tool intentionally does not invent a hybrid file format.

Handling and Distributing the Private Key Safely

RSA private keys are bearer credentials. Anyone who obtains the PKCS#8 PEM block can decrypt every ciphertext the matching public key produces, so the private output deserves the same handling as a root password. Generate once, copy the public key to the consumer, transfer the private key directly into protected storage, and run the protocol-level round trip described above. Do not paste the private key into source control, ticketing systems, chat tools, analytics dashboards, browser sync, or ordinary notes. Close the tab and clear clipboard history after securely importing the key, and rotate immediately if the private key is ever exposed. For production identity or TLS, prefer the key-generation workflow provided by the owning platform or hardware security module rather than a browser-based tool.

The tool does not password-protect the private PEM because the Web Cryptography API exports PKCS#8 bytes without a password envelope. Adding a passphrase envelope outside the browser is possible but changes the format and breaks the round-trip test described above; perform any re-encryption only after the unprotected key has been verified to work end to end. Browser extensions, clipboard managers, malware, and screenshots all sit outside the Web Crypto boundary, so use a trusted patched device when generating keys.

Verifying RSA Keys with an End-to-End Test

A PEM that imports successfully does not guarantee compatible parameters. RSA-OAEP exposes several knobs — hash algorithm, label, and mask-generation function — and a peer that defaults to SHA-1 or a different label will accept the key and then fail at decryption. The verification contract used by the RSA Key Generator locks eight external parameter invariants, exports both envelopes, imports the generated SPKI and PKCS#8 back into Web Crypto, encrypts a known UTF-8 message with the public key, and asserts exact recovery with the private key. The imported algorithm must also report the selected modulus length. Repeat that round trip with the actual application protocol — SSH key exchange, TLS handshake, or custom RSA-OAEP call — before relying on any key in production.

Random output is expected: generating twice with identical settings must produce different keys, because secure generation must be random and cannot be tested against a fixed golden value. Generation is asynchronous and a job identity prevents an older request from overwriting newer settings if you change parameters mid-generation. The private and public outputs are kept only in component memory until navigation or replacement, although browser extensions, malware, clipboard managers, and screenshots remain outside that boundary. Treat the key as live the moment the generation completes, and rotate immediately if exposure is suspected.