簡體   English   中英

在Linux中存儲憑證

[英]Storing credentials in linux

我需要訪問需要用戶名和密碼的服務,並且我不希望將其存儲在代碼中。 該代碼在帶有kerberos的linux服務器上運行。

誰能指出允許我在Linux上使用python或bash shell從Linux存儲密碼的示例嗎?

目前,我在文件中使用明文密碼,僅對當前用戶具有權限。

我已經指向使用Powershell的指南:

 #The following command create a txt file containing a encrypted version of #the password string (in this example "P@ssword1"). This is something you do once while #logged on as the account that will eventually decrypt the password ####################################################################################### "P@ssword1" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "C:\\Temp\\Password.txt" ####################################################################################### #In your script that are using the encrypted password, you can do the following: ####################################################################################### # 1) Read the encrypted password from the txt file and convert it to a SecureString object $pass = Get-Content "C:\\Temp\\Password.txt" | ConvertTo-SecureString # 2) Convert the SecureString object to a plain text variable that can be used in the script #The decrypted password is now available in the $UnsecurePassword variable. $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass) $UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) cls Write-Host $UnsecurePassword 

為了存儲配置值,我建議使用configparser ,它將允許您將任何類型的配置和參數存儲在配置文件中。

當然,存儲用戶名和密碼非常敏感。 一種方法是使用只有您知道並且不會在任何地方進行硬編碼的主密鑰來加密數據。 相反,每次運行或啟動腳本時,您只需提示輸入主密鑰,然后解密配置文件中存儲的加密密碼即可。 這種方法是解釋在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM