How to add wsl command line arguments to Windows Terminal configuration? - windows-subsystem-for-linux

I have the following .json configuration for my Windows Terminal:
{
"guid": "{926758ba-8c4a-5c36-a9c6-0c4943cd78a1}",
"hidden": false,
"name": "Fedora-33",
"source": "Windows.Terminal.Wsl"
},
This was generated automatically from the WSL database.
I would like to add wsl command line option -u user as it starts now as root. I tried adding
"user" : "hxv454"
to no avail. How can I configure WT to start my wsl instance with a specific user?

Learning from
How do I get Windows 10 Terminal to launch WSL?
searching for "wsl" I have found and used
"commandline": "wsl -d Fedora-33 -u hxv454"
and it worked.

Related

Autoselect Certificate for Chrome

Hello and thanks for help in advance!
I try to configure a Raspberry in Kiosk-Mode to show some website.
Problem: the AutoSelectCertificateForUrls doesn't work, because if I open chrome://policy the policy has no value set.
My .json file, placed under etc/chromium/policies/managed/auto_select_certificate.json
{
"AutoSelectCertificateForUrls": [
"{\"pattern\":\"https://adress.adress/somewhere\",\"filter\":{\"ISSUER\":{\"CN\":\"issuer.CN\“}}}“
]
}
Also tried
[
"{\"pattern\":\"https://adress.adress\",\"filter\":{}}"
]
Because I just didn't got it to work, I tried a different approach.
In my case (Kiosk Mode) I don't need anything other than a one-time klick on "OK" (selecting the certificate). So I used xdotool to realize that.
sudo apt-get install xdotool -y
Create a script containing
#!/bin/sh
export DISPLAY=":0"
export XAUTHORITY="/home/pi/.Xauthority"
sleep 30 # To make sure the window is really loaded
xdotool getactivewindow
xdotool key KP_Enter
Make the script executable via "sudo chmod +x /etc/chromium/select_certificate"
Before "exit 0"! Append "/etc/chromium/select_certificate &" to "/etc/rc.local" to execute it every startup

How to use SSHPass with WSL to autostart & login a session

This might seem a little confusing, but I have a server I want to SSH into but the password is kinda long and complex, I understand for security I shouldn't save my password in plain text but for my convenience, I'm not too worried. Regardless, I'm trying to make it so I can just start up a Linux distro in WSL that automatically connects me to my SSH server and logs in but I'm having trouble. My settings.json block looks kinda like:
{
"guid": "{46ca431a-3a87-5fb3-83cd-11ececc031d2}",
"hidden": false,
"name": "SSH",
"source": "Windows.Terminal.Wsl",
"commandline": "/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no user#host"
},
then when I start that distro I get:
[error 0x80070002 when launching `/usr/bin/sshpass -p 'password' ssh -o StrictHostKeyChecking=no user#host']
Is there another way to do this? And yes I have sshpass installed on literally all my distros just to be 100% sure. I googled around for an sshpass Windows version but can't find it. I've also tried just using sshpass instead of /usr/bin/sshpass but it doesn't work either.
As far as I know error 0x80070002 is a file not found error, but I don't know where the command isn't being found. Does the "commandline" setting get loaded before even the Linux Kernel? Is there a way to launch the command AFTER Linux initializes?
Like the picture below, you should add the fingerprint to the .ssh/known_hosts file first.
Then add sshpass command line to the Window Termial settings.

Ansible to Open Terminal and Run Program on Remote Ubuntu Machine

I'm using Ansible to setup an instance of Ubuntu 18.04 (remote) and run certain programs within the user environment. I have a command I'd like to execute inside a terminal on the remote that requires the terminal stay open.
If I'm on Ubuntu and run the following command I get exactly what I expect.
# DISPLAY=:0 nohup gnome-terminal -- roscore
Use the current display for the user
nohup so the terminal won't close if the parent terminal closes
start a new gnome-terminal instance
-- = run a command inside the new gnome-terminal instance
roscore can be replaced by any command that requires an open stream to a terminal window
My Ansible task looks like this when trying to recreate the same command
- name: Start terminal on remote machine
shell:
args:
cmd: DISPLAY=:0 nohup gnome-terminal -- roscore
executable: /bin/bash
When running this command I get the following verbose output
changed: [] => {
"changed": true,
"cmd": "DISPLAY=:0 nohup gnome-terminal -- roscore",
"delta": "0:00:00.243119",
"end": "",
"invocation": {
"module_args": {
"_raw_params": "DISPLAY=:0 nohup gnome-terminal -- roscore",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": "/bin/bash",
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"rc": 0,
"start": "",
"stderr": "nohup: ignoring input",
"stderr_lines": [
"nohup: ignoring input"
],
"stdout": "",
"stdout_lines": []
}
When I execute this it appears that the terminal is opened for just a moment on the remote machine but it does not stay open. What is Ansible doing that would close the remote terminal session after running the command?
What I want is an Ansible task that will allow a terminal window to open on a remote Ubuntu 18.04 machine. Stretch goal would be to get the command running in the now open terminal.
Any help would be appreciated and glad to clarify where needed. Thank you!
I've decided to go a different direction but wanted to post what I learned.
To execute a command from Ansible that will open a terminal window on the Ubuntu 18.04 (remote) machine will require the following command:
- name: Start terminal on remote machine
shell:
args:
cmd: DISPLAY=:0 nohup gnome-terminal </dev/null >/dev/null 2>&1 &
executable: /bin/bash
Notice the </dev/null >/dev/null 2>&1 &. This is necessary for Ansible to be able to disown the process while allowing the terminal to remain open on the remote machine.
In Theory, I haven't proven this but to run a command inside the terminal would require an extra gnome-terminal argument -e.
-e, --command=STRING
Execute the argument to this option inside the terminal.
Example
- name: Start terminal on remote machine
shell:
args:
cmd: DISPLAY=:0 nohup gnome-terminal -e "bash -c 'whoami'" </dev/null >/dev/null 2>&1 &
executable: /bin/bash

Shared connection to server failed (trying to run an Ansible playbook)

I am quite new to SSH servers and Ansible so this might be a dumb question.
Tried to run an Ansible playbook whilst accessing the server with a private key using the bash command below.
ansible-playbook dbserv.yml -i hosts --limit local-servers --private-key=(where I put the private key)
However, I am getting this error:
fatal: [xxx]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "setup"
},
"module_stderr": "Shared connection to xxx closed.\r\n",
"module_stdout": "/bin/sh: 1: /usr/bin/python2.7: not found\r\n",
"msg": "MODULE FAILURE" }
I have Python installed on my computer so I do not understand why I am getting this error.
OS environment:
Ubuntu 16.04.1
The error message you get is:
/usr/bin/python2.7: not found
Ansible requires the target machine to have Python installed in order to work properly (see Managed node requirements).
The most likely reason is that your target is Ubuntu 16.04 which does not come with Python 2 installed. In this case you need to install it or try the experimental support for Python 3.
If Python 2.7 is installed in a different directory, you can add a host variable, for example in your inventory file (assuming the hostname is xxx as in your question`):
xxx ansible_python_interpreter=/path/to/python2.7
To run modules with Python 3 (experimental), set:
xxx ansible_python_interpreter=/usr/bin/python3
Note: Ansible by default looks for /usr/bin/python, so it's likely that your playbook, inventory file, or ansible.cfg already contain settings for /usr/bin/python2.7 which does not exist on the target machine.

How to access accurev workspace from new machine

I have a workspace in accurev. Recently I had to change my machine and now I want to setup the accurev workspace on the new machine. When I access my workspace from GUI, it shows old system name saying the workspace is on old system and cannot be accessed from new machine.
Is there any way I can get the same workspace on the new machine? or do I need to create a new workspace on new machine?
This can be done from Accurev GUI.
Goto View -> Workspace.
It will show a list of workspaces you created earlier. Select the workspace you want to modify, right-click and choose Edit. It will open a window for you to enter the path on your new machine (browse to the location on your new machine). Follow the steps clicking next button.
Clicking Finish will update the system with the chosen location and with your new machine as the host name.
Look into "AccuRev chws":
CHWS
change the name and/or definition of a
workspace
USAGE
accurev chws -w
accurev chws -w <workspace> [ -l <new-location> ] [ -m <new-machine> ]
[ -b <new-backing-stream> ] [ -k <kind> ] [ -e <eol-type> ]
accurev chws -s ...
Look particularly at -l and -m.