Forum Discussion
What is the path to a user's home directory from root?
I have a PowerShell script that uploads a pfx file using psftp.exe from PuTTY. When I first sftp'd to the BIG-IP I created a folder named "cert", and the path is /home/USERNAME/cert. I upload the pfx file. My problem is I have another PowerShell script that imports the pfx file. Here's my code:
if ( (Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn"}) -eq $null ){ Add-PSSnapIn iControlSnapIn }
$bigip_name = 'QA' $user = 'USERNAME' $pass = 'Password'
$bigip = New-Object -TypeName iControl.Interfaces; $success = $bigip.initialize($bigip_name, $user, $pass);
$bigip.ManagementPartition.Set_active_partition("Common");
$mgmtmode = New-Object -TypeName iControl.ManagementKeyCertificateManagementModeType $mgmtmode.value__ = 0
$SSLDir = "E:\PowerShell\SSL\IssuedCerts\PFXs"
$url = "test.hanktest22.com"
$pfxfilename = $url + ".pfx" $pfxfile = "/home/USERNAME/cert/" + $pfxfilename
$exportPass = "exportPass" Set-Location -Path $SSLDir $bigip.ManagementPartition.Set_active_partition("Common")
$bigip.ManagementKeyCertificate.pkcs12_import_from_file( ($mgmtmode), ($url), ($pfxfile), ($exportPass), ($true) )
This worked the other day, however it isn't working today. I believe I can't see that folder and perhaps the home folder is an alias for a longer path.
Thanks in advance for the help!
Hank
- R_Eastman_13667Historic F5 Account
Login to the F5, then:
run /util bash printenv | grep HOME
This will give you the path to the home directory for the user you logged in with. By default /root is the HOME directory for all admin users.
- Hank_StallingsNimbostratus
I figured it out, all I had to do was change my upload path to the one that worked previously.
POWERSHELL CODE TO UPLOAD CERTIFICATE TO BIG-IP:
$workdir = "E:\PowerShell\SSL\IssuedCerts\PFXs" $certficate = "www.hanktest24.com" $Hostname = "bigIP" $user = "USERNAME" $pass = "PASSWORD" $psftpdir = "E:\Program Files (x86)\PuTTY" $remotedir = "/shared/cert" $tempContent = $() $tempContentFile = "$($workdir)\temp_put.txt" $tempContent += "cd cert " $tempContent += "nput $workdir"+"\"+"$certficate " $tempContent += "nexit " $tempContent += "exit " $out = Out-File -FilePath $tempContentFile -InputObject $tempContent -Encoding ASCII; Set-Location -Path $psftpdir $out = & .\psftp.exe $($Hostname) -l $($user) -pw $($pass) -b $($tempContentFile))
POWERSHELL CODE TO IMPORT THE CERTIFICATE:
if ( (Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn"}) -eq $null ){ Add-PSSnapIn iControlSnapIn } $bigip_name = 'bigIP' $user = 'USERNAME' $pass = 'PASSWORD' $bigip = New-Object -TypeName iControl.Interfaces; $success = $bigip.initialize($bigip_name, $user, $pass); $bigip.ManagementPartition.Set_active_partition("Common"); $mgmtmode = New-Object -TypeName iControl.ManagementKeyCertificateManagementModeType $mgmtmode.value__ = 0 $SSLDir = "E:\PowerShell\SSL\IssuedCerts\PFXs" $url = "WWW.hanktest24.com" $pfxfilename = $url + ".pfx" $pfxfile = "/shared/cert/" + $pfxfilename $exportPass = "EXPORTPASS" Set-Location -Path $SSLDir $bigip.ManagementPartition.Set_active_partition("Common") $bigip.ManagementKeyCertificate.pkcs12_import_from_file( ($mgmtmode), ($url), ($pfxfile), ($exportPass), ($true) )
Hope this helps others, because I've been trying to figure this out for months! Appreciate the help of Joe Pruitt!
Thanks,
Hank
- LanceHall_17749Nimbostratus
Hi,
I have done exactly what you said here and I am still struggling with getting this done.
On the upload of the cert (your first script). I get this error. I am using the admin account on my test F5.
psftp.exe : Using username "admin".
I then decided to try and upload the cert manually using psftp outside of the powershell and I managed to create a folder called shared/cert and place my cert in there.
Then in the import of the cert I get this error.
error_string : error:02001002:system library:fopen:No such file or directory"
This is so frustrating because I feel like I am close. Please could you help me here.
Thank you, Lance
- LanceHall_17749Nimbostratus
Hi,
I have done exactly what you said here and I am still struggling with getting this done.
On the upload of the cert (your first script). I get this error. I am using the admin account on my test F5.
psftp.exe : Using username "admin".
I then decided to try and upload the cert manually using psftp outside of the powershell and I managed to create a folder called shared/cert and place my cert in there.
Then in the import of the cert I get this error.
error_string : error:02001002:system library:fopen:No such file or directory"
This is so frustrating because I feel like I am close. Please could you help me here.
Thank you, Lance
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com