Python Quick Tip: Hiding Passwords and Secret Keys in Environment Variables (Mac & Linux)

Python Quick Tip: Hiding Passwords and Secret Keys in Environment Variables (Mac & Linux)

Corey Schafer

6 лет назад

161,494 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Idris Ali
Idris Ali - 19.09.2023 19:17

in linux after you save your enviroment variables you have to type source .bashrc before restarting your text editor :)

Ответить
Paul Arthur
Paul Arthur - 10.06.2023 04:38

how is having plain text passwords in environment variables secure?

Ответить
doc_ineeda _win
doc_ineeda _win - 18.05.2023 02:28

some reason i just get print of none

Ответить
brisk walk
brisk walk - 24.04.2023 11:20

And what about the .env file?

Ответить
Vishal Patel
Vishal Patel - 11.01.2023 22:06

Instead of using os.environ.get(), you can now just use os.getenv()

Ответить
Farrah Xie
Farrah Xie - 05.12.2022 20:40

Thank you for your help!!

Ответить
Rilly V
Rilly V - 30.11.2022 13:15

This video is outdated for latest version of mac

Ответить
Zippidee Doodah
Zippidee Doodah - 28.10.2022 22:40

Why does this print?
None
None

Ответить
Pujan raj Rai
Pujan raj Rai - 13.10.2022 12:16

million 🔥
Congratulations

Ответить
Yo
Yo - 23.09.2022 16:28

Easy & fantastic tutorial ! I will definitely use this method to hide my credentials on python boto3 script lol

Ответить
Joe Goldberg5254
Joe Goldberg5254 - 17.07.2022 18:10

Amazing

Ответить
Ol'seun Iyadi
Ol'seun Iyadi - 27.06.2022 23:02

Is there a way to parse this to Powershell?

Ответить
FrocketGaming
FrocketGaming - 16.06.2022 23:05

I've been searching for a solution like this for several days... this solved so many of my headaches.

Ответить
Jorge Escobar
Jorge Escobar - 12.06.2022 18:33

I used a pip3 package o do this, but now I think this is simpler and easier..

Ответить
vardhan negi
vardhan negi - 30.05.2022 09:10

use this cmd `source .bash_profile` after saving the `.bash_profile` file

Ответить
Topher Judd
Topher Judd - 19.05.2022 12:15

I keep getting a smtplib.SMTPSenderRefused on video 0 of flask series
How do I check that my environmental variables are correct?

Ответить
ElGary
ElGary - 17.05.2022 21:02

LOVE IT, nobody has explained better! thanks a lot!

Ответить
Ankita Burman
Ankita Burman - 25.04.2022 11:53

Corey MS ❤️❤️❤️❤️ your python videos are pure gold 🥰🥰🥰🥰🥰

Ответить
rafael solorzano
rafael solorzano - 29.03.2022 19:19

thx

Ответить
Jermaine Aw
Jermaine Aw - 22.03.2022 06:21

Hi Corey! Great video. If I input print(EMAIL_ADDRESS, should I get 'None' as my output?

Ответить
Ben Radburnd
Ben Radburnd - 01.03.2022 08:23

How do you make this work using a virtual environment?

Ответить
Ivan Raineri
Ivan Raineri - 16.01.2022 00:12

Thank You

Ответить
swain
swain - 28.11.2021 23:32

Sir Corey comeback man!!

Ответить
Sławek Drożdż
Sławek Drożdż - 01.11.2021 21:41

nice ;) thx

Ответить
Brittany Marie
Brittany Marie - 06.10.2021 19:09

I'm running Ubuntu 20.04 and the test script returned 'None' for me until I added the environment variables to ~/.bashrc instead of .bash_profile. So, it seems that the proper procedure may vary with each distribution of Linux.

Ответить
Ahmad Faisal
Ahmad Faisal - 17.09.2021 21:06

very helpful, thanks a lot

Ответить
Augustine Okekeoma
Augustine Okekeoma - 23.08.2021 07:59

Talented Teacher. Thanks for your pains. I want to one day build a python package for physics. Your lectures are great help.

Ответить
Leo King
Leo King - 11.08.2021 14:49

Thanks for this quick and concise explanation. Is this any more secure than hard-coding the password however? Couldn't someone cat your .bash_profile to see the password, or perform some other trickery to access it?

Ответить
Trevor Mckellen
Trevor Mckellen - 11.08.2021 10:33

Pretty helpful. But when print the variables, i get a None type back.

Ответить
A2infinite
A2infinite - 28.07.2021 09:26

you saved my life again!

Ответить
krishna thamatam
krishna thamatam - 17.06.2021 13:46

I think I should worship you for the rest of my life. You are always the savior.

Ответить
JESSKETCHES.
JESSKETCHES. - 11.06.2021 13:51

thank you for making sense of this for me - was struggling to understand it in text form only! :)

Ответить
Rakesh PK
Rakesh PK - 29.05.2021 10:14

In my experience, environment variables also serve one important purpose other than maintaining secrecy. By using of environment variables instead of hard coded values I could easily roll out my project without worrying about the API keys and other settings used in the development version updated before uploading source code to the deployment server.🔥

Ответить
Rakesh PK
Rakesh PK - 29.05.2021 09:53

Your explanations are great.

Ответить
Quinn Pisani
Quinn Pisani - 09.05.2021 21:55

no idea what just happened.

Ответить
李百凱
李百凱 - 22.04.2021 11:21

@ Corey Schafer
Thanks for sharing.But it didn't work on AWS linux2 after modify .bash_profile.
How can I do ? Thnak you!!

Ответить
Dinkar Jain
Dinkar Jain - 23.03.2021 20:11

Great information as always, but I was wondering if I could use a separate text file for holding my credentials and then load it into my python module, I can add that text file in my .gitignore so it will not be pushed. I mean it won't be nice if I generate too many environment variables, it would be confusing if I am working on multiple projects.

Ответить
Jack Padalino
Jack Padalino - 21.03.2021 07:11

Hey I'm getting an error when I request a password reset that says 'get_reset_token() missing 1 required positional argument: 'self''. Any idea what could be causing this? I've coped your code from your github so I'm confident I have exactly what you have!

Ответить
Edward Brown
Edward Brown - 19.03.2021 09:01

Still very useful 3 years later. Great videos. Btw, how do you manage credentials on scripts that will be hosted online for instance?

Ответить
Philip Bissiwu
Philip Bissiwu - 16.03.2021 17:34

Hi , Nice tutorial, just a quick question, will this work the same if the code is pushed to a remote server?

Ответить
harsh tripathi
harsh tripathi - 06.03.2021 09:59

How can i be able to access this value in some other machine if I want to??

Ответить
Jackey Zhu
Jackey Zhu - 18.02.2021 20:20

depending on the shell you are using, look for corresponding .xxrc file. (e.g. if you use zsh, .zshrc; if bash, then .bashrc)

Ответить
Steven Even
Steven Even - 04.02.2021 00:15

plz show me how to use this in the virtual env (venv) for windows

Ответить
Aleksander Jaworski
Aleksander Jaworski - 03.02.2021 12:41

How about creating a separate file for security data, then adding that file to gitignore, and reading the necessary data from that file when needed?

Ответить
aziz as
aziz as - 31.01.2021 20:18

I get None

Ответить
PEPE HAOULOMOU
PEPE HAOULOMOU - 19.01.2021 03:33

If you are using Linux Box , the solution is to put your environment variables in "/etc/environment".

Example in your /etc/environment file:
------------------------------------------------------------------------------------
DB_USER="Y=User name"
DB_PASS="Your Password"
-------------------------------------------------------------------------------------
And reboot your computer. you will have access to them in your python files using:

import os
DB_USER=os.environ["DB_USER"]

Ответить
MO ZY
MO ZY - 10.01.2021 17:41

can you save the py file anywhere on the computer ??? does it matter??

Ответить
Phantasm Zero
Phantasm Zero - 08.01.2021 17:17

It didnt work for me i kept getting none

Ответить