jsch + running multiple command in shell after SU and then close channal - jsch

My requirement is as follow:
I have to login to Unix box using my credentials and once login, I have to do su to different user. I need to provide password and reason for scsu command.
once su successful, I have to run set of commands one after another as that user.
On completion of executions, close channel and session both.
I tried to use Shell channel but I am able to fire scsu only ... need help to complete remaining requirement of executions of command and closing channel

Related

Testing if user created in AD can be logged into on a VM

I am a QA automation engineer and in the web app I test there's a feature that creates Active Directory users.
My tools are - Selenium (Java), RemoteWebDriver, Selenium Grid (Docker)
I was trying to find ways to validate this process and came to a stop - this field (AD) is new
to me and I need to find a way to make sure the user was created and can be logged into in the
network.
I was trying to find a way to do this and came up with 2 options, where the first one is the least
preferred way:
Make a request (API? 3rd side tool?) to get the relevant user(s).
The issue:
A user created and registered in the AD doesn't necessarily mean that the client can log into it (at least by the way I understood how AD works), and so it loses the most important consequence of the feature.
Use a VM, get the AD user information (username + password: possible) and try to log into the VM using those details.
The issue:
I haven't came across a tool that does it, the closest thing is Robot class or WinAppDriver.
WinAppDriver seems like the best solution as of now although I don't know how to make the login process work since it's the process starts before the desktop is open and I don't know how to locate the username and password field, so I figured using Robot class seems like the simplest solution, if it works on a VM that is, which as of now doesn't seem like it does.
So, before advancing on learning how to use WinAppDriver with my current automation, I'd like and appreciate your opinions about the matter or if you have simpler solutions.
Thank you very much for reading!
• We can check whether a user is created successfully or not and if that user can log in to the AD domain or not by executing a script as below. It is a powershell script that auto logs in through remote desktop protocol in the other domain joined VM from an Azure domain joined VM that checks whether the recently created user can login or not.
Powershell script : -
cmdkey /list | ForEach-Object{if($_ -like "*target=TERMSRV/*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}
echo "Connecting to 192.168.1.100"
$Server="192.168.1.100"
$User="Administrator"
$Password="AdminPassword"
cmdkey /generic:TERMSRV/$Server /user:$User /pass:$Password
mstsc /v:$Server
• In the above script, replace the ‘$user’ value by the user principal name of the newly created user, i.e., ‘$User=”testdemo#example.com”’ and the ‘$Password’ value by the password set for that user. Also, ensure that you replace and enter the correct IP address of the domain controller/AD server. Also, ensure that before executing the above powershell script, execute the below commands in an elevated (administrator privileges) powershell console.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Lastly, please ensure that while creating the user, the option ‘User must change password at next logon’, ‘Account is Disabled’, ‘Password never expires’ and ‘User cannot change password’ are unchecked and not selected.
• Also, you can use the below command line script for logging in to the domain joined Azure VM through RDP protocol. In the below command, replace the ‘username’ and ‘password’ with the username and password of the user created recently to log in to the Azure VM with this command line script. Also, replace the ‘TERMSRC’ with the hostname of the server system or the domain joined VM where the specified UNC path is located and replace the ‘some_unc_path’ with the actual path UNC path of the shared directory folder. Please execute the below command through elevated (administrator privileges) command prompt.
Command script: -
c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nolog -command cmdkey /generic:TERMSRC/some_unc_path /user:username /pass:pa$$word; mstsc /v:some_unc_path

TWS job failing. ERROR jobmon was unable to retrieve user information

I am configuring TWS job in one of our application windows server but when the job triggered it is throwing the below exception. I am using domain user to execute the job.
AWSBDW079E Jobman could not run the job because the system call used to launch the job failed: Jobmon was unable to retrieve user information.
Do I need any special permissions for the user to run the job.
Any help?
On Windows, TWS needs userid and password in order to impersonate the user.
You have to specify the USER object with the appropriate Workstation name, userid and password.
Using Dynamic Agents there are also other options using Executable job types, e.g. you can store the password locally on the agent with the parm utility.
I have figured out the issue. The issue was with the user permissions. The user which is used to run the job on the workstation must have the below permissions.
Allow log on locally
Log on as a batch job

Forgot sonarqube password. Using it locally, No Database

I am using sonarqube from command line. I have a local server (sonarqube 64) on my windows 7 (x86-64). I successfully installed and I can open the web host http://localhost:9000/. but I cannot login the admin/admin login details are not working.
I know there is way of resetting the password but I need database that I don't have and i am the only user/admin.
Is there any way to recover the password or change it? should I uninstall the server and install it again?
It is not said how to properly unistall the server either
Thanks
I'm running 8.5 and this appears to be different, I used:
Change directory to /opt/sonarqube/lib/jdbc/h2
cd /opt/sonarqube/lib/jdbc/h2
Run the command line below to open h2 shell
java -cp h2-1.4.199.jar org.h2.tools.Shell
you will be prompted to fill the following:
URL jdbc:h2:tcp://localhost:9092/sonar
Driver org.h2.Driver
User [none]
Password [none]
You will be prompted now to sql command line (sql>), then type your query:
update users set crypted_password = '$2a$12$uCkkXmhW5ThVK8mpBvnXOOJRLd64LJeHTeCkSuB3lfaR2N0AYBaSi', salt=null, hash_method='BCRYPT' where login = 'admin'
There is no real "installation" for SonarQube; you explode the zip and run one of the start scripts. So if you do decide to scrap your current instance, all you need to do is shut it down, delete the directory and re-explode the zip. However, once you do that, you should seriously consider connecting it to a production database. So far you're running with the embedded H2 database, and that's not appropriate for long-term use. Among other things, migration to new versions is not supported for the H2 database.
Once you've done that, you can reset the admin password by executing the following query:
update users set crypted_password = '88c991e39bb88b94178123a849606905ebf440f5', salt='6522f3c5007ae910ad690bb1bdbf264a34884c6d' where login = 'admin'
That sets it back to 'admin'
For the config below (openjdk-11, sonarqube-8), follow the steps:
Change directory to /opt/sq/lib/jdbc/h2
cd /opt/sq/lib/jdbc/h2
Run the command line below to open h2 shell
java -cp h2-1.3.176.jar org.h2.tools.Shell
you will be prompted to fill the following:
URL jdbc:h2:localhost:9000/data/sonar
Driver org.h2.Driver
User sonar
Password sonar
You will be prompted now to sql command line (sql>), then tap your query:
update users set crypted_password = '88c991e39bb88b94178123a849606905ebf440f5', salt='6522f3c5007ae910ad690bb1bdbf264a34884c6d' where login = 'admin'

how to deal with ipmitool sol session which looks frozen

I use ipmitool SOL session to get console logs from remote server. Initially session is responsive. If I hit enter, I can see login message to remote server like below.
[SOL Session operational. Use ~? for help]
<hostname> login:
But if I don't hit enter after activating session and try to press enter or any key, it does not do anything. I can see only this line:
[SOL Session operational. Use ~? for help]
I am not sure if the session becomes frozen or not. I can see help after pressing ~? but it is not helpful to resolve the issue. I don't see that login message again.
Is there way to generate some logs on this session without shutting off remote server ? And what are the ways to deal with frozen sol sessions ?
UPDATE
I create SOL sessions by using this command:
ipmitool -I lanplus -U <ipmi-username> -P <ipmi-password> -H <ipmi-ip> sol activate
Type "~." to quite the SOL session.
Reference: https://advantech-ncg.zendesk.com/hc/en-us/articles/360021053132-How-to-use-SOL-serial-over-lan-

Unable to supply password to runas from commandline

I am unable to supply password to runas from commandline
I have tried the following
cmd /C echo my_admin_password | runas /user:DOMAIN\my_admin_login c:\test.bat
and
echo my_admin_password | runas /user:DOMAIN\my_admin_login c:\test.bat
And the error I get is
Attempting to start c:\test.bat as user "DOMAIN\my_admin_login" ...
RUNAS ERROR: Unable to run - c:\test.bat
1326: Logon failure: unknown user name or bad password.
How do I fix this?
Take a look at this link: runas utility
It's a runas free utility that have the follwing features:
It accepts password as a command line parameter so that it can be used in batch files.
It can bind started process to the interactive user Desktop so it can be used to start interactive processes from various services such as 24x7 Scheduler, 24x7 Event Server and other.
Note: Professional version of RunAs also supports encryption of the entire command line, which administrators can use to give regular users access to certain programs requiring admin-level privileges. Users don't need to know the administrator's password and cannot use it to run anything else… simple, yet very efficient solution for this common problem.
Also you can try pass the password as input for the process using subprocess.Popen.communicate or even subprocess.Popen.stdin.write.
Other interesting links:
How to pass a password to a process?
Command-line runas with password
PsExec