How to access your 2FA Docker Hub account from the command line

With 2FA enabled on your Docker Hub account, you'll find you cannot access it with your user password from within the CLI. Jack Wallen shows you how to make this work.

How to access your 2FA Docker Hub account from the command line With 2FA enabled on your Docker Hub account, you'll find you cannot access it with your user password from within the CLI. Jack Wallen shows you how to make this work.

If you've recently added two-factor authentication (2FA) to your Docker Hub account, you've more than likely run into a situation where you can no longer access the account from the command line using the standard username/password credentials. Although this might be a bit of a headache, it's one you'll want to work through. Why? Because in this day and age you need as much security as you can get.

So instead of either ignoring 2FA on your Docker Hub account, or disabling it the second you can't gain access from the CLI, let's fix that problem.

SEE: Mastermind con man behind Catch Me If You Can talks cybersecurity (TechRepublic download)

What you'll need

The only things you'll need to make this work are:

  • A Docker Hub account with 2FA enabled 

  • A desktop client that allows you to access Docker Hub from the CLI

  • A Docker Hub access token

I'll show you how to obtain the access token, but you'll need to have the other bits in place.

How to get your Docker Hub access token

The first thing to do is to get your Docker Hub access token. To do that log into your Docker Hub account. Click on your profile image in the upper right corner and select Account Settings (Figure A).

Figure A

dockerhub2faclia.jpg

The Docker Hub profile menu.

From within Account Settings, click Security in the left sidebar (Figure B).

Figure B

dockerhub2faclab.jpg

The Security entry in the Docker Hub sidebar.

Under Access Tokens, click New Access Token (Figure C).

Figure C

dockerhub2faclic.jpg

Creating a new Access Token for Docker Hub.

In the resulting window (Figure D), give the token a name and click Create.

Figure D

dockerhub2faclid.jpg

Naming your access token.

Finally, you'll be presented with your token (Figure E). Copy and save that token in a safe location. Once you dismiss this token you cannot retrieve it as it is not stored. Click Copy And Close and the token will be copied to your desktop clipboard.

Figure E

dockerhub2faclie.jpg

Your access token is ready.

How to log in to Docker Hub

On the system, you'll be logging in to Docker Hub, open a terminal window and issue the command:

docker login --username NAME

Where NAME is your Docker Hub username.

When prompted for a password, paste your access token and hit Enter. If you try to use your Docker Hub user password, the login will fail. With your access token the login will succeed and you're ready to start working.

Congratulations, you now can access your Docker Hub 2FA-enabled account from the command line. Enjoy that added layer of security.

Also see

Internet security concept

Image: Getty Images/iStockphoto