2017-08-09 12 views
0

ユーザ名とパスワードが必要なサービスにアクセスする必要があります。これはコードに保存しません。このコードは、Kerberosを持つLinuxサーバー上で動作します。資格情報を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 "[email protected]"). This is something you do once while 
#logged on as the account that will eventually decrypt the password 
####################################################################################### 
"[email protected]" | 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 
+0

暗号化されたパスワードをファイルに入れるのはあまり意味がありません。スクリプトには解読キーが含まれている必要があります。そのため、スクリプトを読むことができる人は誰でも、ファイル内のパスワードを解読できます。 – Barmar

+0

@Barmar >> Powershellトリックに関連するWindowsの魔法がい​​くつかあります。つまり、暗号化されたファイルを別のマシンにコピーしたり、別のユーザーのセッションからアクセスすると、「automagic」キーを使用できなくなります。 OK、Windowsに複数の権限エスカレーションの問題がありますが、それは別の問題です... –

+0

[私はPythonでユーザー名とパスワードを安全に保存する必要があります。どのようなオプションがありますか?](https://stackoverflow.com/questions)/7014953/i-need-to-secure-store-a-username-and-password-in-python-what-are-my-options) –

答えて

0

設定値を格納するために、私はあなたが設定ファイルに設定し、パラメータのいずれかの種類を保存することができますどのconfigparserを使用してお勧めします。

ユーザー名とパスワードの格納は、もちろん非常に機密です。 1つの方法は、あなただけが知っていてどこにでもハードコードされていないマスターキーでデータを暗号化することです。代わりに、スクリプトを実行または起動するたびに、そのマスターキーの入力を求めるだけで、設定ファイルに格納されている暗号化されたパスワードを解読できます。このアプローチはhereで説明されています。

関連する問題