DBA Hub

📋Steps in this guide1/7

EMCLI : Manage Credentials using Enterprise Manager Command Line Interface (Cloud Control)

This article describes how to manage credentials in Enterprise Manager Cloud Control using EMCLI, rather than using the web interface.

oracle miscconfigurationintermediate
by OracleDba
16 views
1

Setup

You can perform these actions from anywhere with an EMCLI client , but for this example we're going to use the EMCLI client on the Cloud Control server. We use the following commands to connect to the OMS and sync the EMCLI client.

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
unset SSH_ASKPASS
export OMS_HOME=/u01/app/oracle/middleware
export AGENT_HOME=/u01/app/oracle/agent/agent_inst
alias emcli='${OMS_HOME}/bin/emcli'

emcli login -username=sysman
emcli sync
2

Add Host Credential

The verb allows you to create a named credential. The and properties determine what type of credential it is. The following example adds a named host credential (HostCreds).

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
HOST_CREDENTIAL_NAME="NC_HOST_MY_HOST"
HOST_USERNAME="oracle"
HOST_PASSWORD="MyPassword123"

emcli create_named_credential \
  -cred_name="${HOST_CREDENTIAL_NAME}" \
  -auth_target_type="host" \
  -cred_type="HostCreds" \
  -attributes="HostUserName:${HOST_USERNAME};HostPassword:${HOST_PASSWORD}"
3

Add Database Credential

The following examples use the verb to create database credentials (DBCreds). In addition to the username (DBUserName) and password (DBPassword), we must specify the role (DBRole). There are examples for non-CDB and CDB credentials.

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
DB_CREDENTIAL_NAME="NC_DB_NORMAL"
DB_USERNAME="MY_USER"
DB_PASSWORD="MyPassword123"
DB_ROLE="normal"

emcli create_named_credential \
  -cred_name="${DB_CREDENTIAL_NAME}" \
  -auth_target_type="oracle_database" \
  -cred_type="DBCreds" \
  -attributes="DBUserName:${DB_USERNAME};DBPassword:${DB_PASSWORD};DBRole:${DB_ROLE}"

DB_CREDENTIAL_NAME="NC_DB_SYSDBA"
DB_USERNAME="MY_USER"
DB_PASSWORD="MyPassword123"
DB_ROLE="sysdba"

emcli create_named_credential \
  -cred_name="${DB_CREDENTIAL_NAME}" \
  -auth_target_type="oracle_database" \
  -cred_type="DBCreds" \
  -attributes="DBUserName:${DB_USERNAME};DBPassword:${DB_PASSWORD};DBRole:${DB_ROLE}"

DB_CREDENTIAL_NAME="NC_DB_CDB_NORMAL"
DB_USERNAME="C##MY_USER"
DB_PASSWORD="MyPassword123"
DB_ROLE="normal"

emcli create_named_credential \
  -cred_name="${DB_CREDENTIAL_NAME}" \
  -auth_target_type="oracle_database" \
  -cred_type="DBCreds" \
  -attributes="DBUserName:${DB_USERNAME};DBPassword:${DB_PASSWORD};DBRole:${DB_ROLE}"

DB_CREDENTIAL_NAME="NC_DB_CDB_SYSDBA"
DB_USERNAME="C##MY_USER"
DB_PASSWORD="MyPassword123"
DB_ROLE="sysdba"

emcli create_named_credential \
  -cred_name="${DB_CREDENTIAL_NAME}" \
  -auth_target_type="oracle_database" \
  -cred_type="DBCreds" \
  -attributes="DBUserName:${DB_USERNAME};DBPassword:${DB_PASSWORD};DBRole:${DB_ROLE}"
4

Remove Credential

The verb can delete any named credential, host or database. The example below deletes a credential owned by the SYSMAN user.

Code/Command (click line numbers to comment):

1
2
3
4
5
6
CREDENTIAL_NAME="NC_HOST_MY_HOST"
CREDENTIAL_OWNER="SYSMAN"

emcli delete_named_credential \
  -cred_owner="${CREDENTIAL_OWNER}" \
  -cred_name="${CREDENTIAL_NAME}"
5

Set Host Preferred Credential

The verb allows you set a preferred credential. A host credential can be for a normal user (HostCredsNormal), or a privileged user (HostCredsPriv) that can perform operations. The following examples show how to set each type of preferred credential.

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
HOST_NAME="my-host.localdomain"
HOST_CREDENTIAL="NC_HOST_MY_HOST"

emcli set_preferred_credential \
  -set_name="HostCredsNormal" \
  -target_type="host" \
  -credential_name="${HOST_CREDENTIAL}" \
  -target_name="${HOST_NAME}"

emcli set_preferred_credential \
  -set_name="HostCredsPriv" \
  -target_type="host" \
  -credential_name="${HOST_CREDENTIAL}" \
  -target_name="${HOST_NAME}"
6

Set Database Preferred Credential

An Oracle database has three distinct preferred credentials (DBCredsNormal, DBCredsSYSDBA and DBHostCreds). The following examples use the verb to set all of them.

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
DB_NAME="orcl"
DB_NORMAL_CREDENTIAL="NC_DB_NORMAL"
DB_SYSDBA_CREDENTIAL="NC_DB_SYSDBA"
DB_HOST_CREDENTIAL="NC_HOST_MY_HOST"

emcli set_preferred_credential \
  -set_name="DBCredsNormal" \
  -target_type="oracle_database" \
  -credential_name="${DB_NORMAL_CREDENTIAL}" \
  -target_name="${DB_NAME}"

emcli set_preferred_credential \
  -set_name="DBCredsSYSDBA" \
  -target_type="oracle_database" \
  -credential_name="${DB_SYSDBA_CREDENTIAL}" \
  -target_name="${DB_NAME}"

emcli set_preferred_credential \
  -set_name="DBHostCreds" \
  -target_type="oracle_database" \
  -credential_name="${DB_HOST_CREDENTIAL}" \
  -target_name="${DB_NAME}"
7

Help

The usage of the commands referenced in this article can displayed using the following commands. You can also check out all the other credential verbs in the Help Command Output . For more information see: - EMCLI : All Articles Hope this helps. Regards Tim...

Code/Command (click line numbers to comment):

1
2
3
4
5
emcli help create_named_credential
emcli help delete_named_credential
emcli help set_preferred_credential

emcli help

Comments (0)

Please to add comments

No comments yet. Be the first to comment!