百度智能云

All Product Document

          Cloud Compute Service

          Key Pair

          Create an key-pair

          Individual users can create 500 key pairs in the region by default (sum of created and imported key pairs). The created key pair can be embedded into the instance to log in to the virtual machine remotely:

          public static void createKeypair(BccClient bccClient, String keyName, String keyDes) {
          
              KeypairCreateRequest keypairCreateRequest = new KeypairCreateRequest();
          
              // Set a key name
          
              keypairCreateRequest.setName(keyName);
          
              // Set key descriptions
          
              keypairCreateRequest.setDescription(keyDes);
          
              bccClient.createKeypair(keypairCreateRequest);
          
          }

          Import a Key Pair

          It is used for users to import the created key pair:

          public static void importKeypair(BccClient bccClient, String keyName, String keyDes, String publicKey) {
          
              KeypairImportRequest keypairImportRequest = new KeypairImportRequest();
          
              // Import key names
          
              keypairImportRequest.setName(keyName);
          
              // Add descriptions
          
              keypairImportRequest.setDescription(keyDes);
          
              // Public key content
          
              keypairImportRequest.setPublicKey(publickey);
          
              bccClient.importKeypair(keypairImportRequest);
          
          }

          Query the Key Pair Details

          It is used to query the single key pair details:

          public static void keypairDetail(BccClient bccClient, String keypairId) {
          
              KeypairIDetailRequest keypairDetailRequest = new KeypairDetailRequest();
          
              // Key Name ID
          
              keypairDetailRequest.setKeypairId(keypairId);
          
              KeypairDetailResponse keypairDetailResponse = bccClient.keypairDetail(keypairDetailRequest);
          
          }

          Bind a Key Pair

          It is used to bind the selected key pair (single key pair only) to the selected virtual machine (multiple virtual machines supported). At present, one virtual machine can only bind a key pair:

          public static void attachKeypair(BccClient bccClient, String keypairId, String instanceIds) {
          
              KeypairAttachRequest keypairAttachRequest = new KeypairAttachRequest();
          
              // Bound a key ID
          
              keypairAttachRequest.setKeypairId(keypairId);
          
              // Instance
          
              keypairAttachRequest.setaddInstance(instanceIds);
          
              bccClient.attachKeypair(keypairAttachRequest);
          
          }

          Unbind a Key Pair

          It is used to unbind the bound key pairs from the selected virtual machine. This operation is only applicable for the virtual machine with the Linux system, and the selected virtual machine must be in the Running or Stopped status:

          public static void detachKeypair(BccClient bccClient, String keypairId, String instanceIds) {
          
              KeypairDetachRequest keypairDetachRequest = new KeypairDetachRequest();
          
              // Bound a key ID
          
              keypairDetachRequest.setKeypairId(keypairId);
          
              // Instance
          
              keypairDetachRequest.setaddInstance(instanceIds);
          
              bccClient.detachKeypair(keypairDetachRequest);
          
          }

          Delete a Key Pair

          It is used to delete a key pair. The key bound with the virtual machine can not be deleted:

          public static void deleteKeypair(BccClient bccClient, String keypairId) {
          
              KeypairDeleteRequest keypairDeleteRequest = new KeypairDeleteRequest();
          
              // Delete a key ID
          
              keypairDeleteRequest.setKeypairId(keypairId);
          
              bccClient.deleteKeypair(keypairDeleteRequest);
          
          }
          Previous
          Security Group
          Next
          zone