How to Use the CMDKEY Command to Manage Stored Credentials on Windows
The cmdkey
command is a Windows utility that lets you create, delete, and manage stored credentials for network authentication. This is particularly useful for automating logins to remote servers or systems where credentials need to be stored securely. In this post, we’ll explore how to use cmdkey
to manage credentials efficiently and safely.
Viewing Stored Credentials
To see the credentials stored on your system, use:
cmdkey /list
This command displays a list of all stored credentials, including the targets they’re associated with, similar to the following:
Target: Domain:target=TERMSRV/127.0.0.1
Type: Domain Password
User: user@domain.local
Local machine persistence
Target: LegacyGeneric:target=git:https://gitlab.com
Type: Generic
User: username
Local machine persistence
Adding New Credentials
You can create a new stored credential using the /add option. For example, the command below can be used to store credentials for a network share. Those credentials will be securely stored and automatically used when accessing the target.
cmdkey /add:SERVER /user:username /pass:password
Deleting Stored Credentials
To delete a specific stored credential, use the /delete option:
cmdkey /delete:SERVER
Why Use Stored Credentials?
One of the most valuable uses of the cmdkey
command is to avoid storing usernames and passwords as plain text in scripts when automating repetitive tasks. For instance, you can add credentials for a remote server before configuring and running a scheduled task that uses those credentials. That way, you don’t have to store the credentials in plain text within your script.
The cmdkey command is a valuable utility for managing stored credentials, especially when working with network resources. By using options like /add, /list, and /delete, you can securely store and manage authentication details for remote systems. Integrate it into your workflow to streamline tasks that require credentials, but always prioritize security.
Average Rating