Prevent VSCode opening as root from WSL - visual-studio-code

When opening VSCode in a folder using code . using my current user, I notice that then it was started as root. The steps that I'm making are to validate this behaviour are:
$ whoami
>> franciscoserrano
$ mkdir test-dir && ll
>> drwxr-xr-x 2 franciscoserrano franciscoserrano 4.0K Jan 18 19:04 test-dir
$ cd test-dir
$ code .
(right after this, inside VSCode's terminal) $ pwd && whoami
/home/franciscoserrano/projects/test-dir
root
Another weird thing is that the VSCode terminal seems to load the .zshrc of my user, this is still inside VSCode terminal:
$ pwd
>> /home/franciscoserrano/projects/test-dir
$ whoami && cd
>> root
$ pwd
>> /home/franciscoserrano
Is this intended? Why making $ cd changes to a directory that is not from the user that outputs $ whoami? How do I force VSCode to open as the same user as in WSL?
Another detail: when creating files inside the same folder, using the VSCode GUI, those are also created as root:
-rw-r--r-- 1 root root 0 Jan 18 19:18 hello.c

Running the following command on the windows side fixes this issue for me:
ubuntu2204.exe config --default-user <wsl-user>

Related

HowTo: Completely Uninstall Postgresql14 from MacOs Catalina If I've used the EnterpriseDB.com GUI installer

I've been trying to get this to work by following the answers in these questions:
How to uninstall postgresql on my Mac (running Snow Leopard)
Completely uninstall PostgreSQL 9.0.4 from Mac OSX Lion?
...but they're not working. So, here's what I have tried instead/in addition...
.
me#myMac:~$ cd /Library/PostgreSQL/14
me#myMac:/Library/PostgreSQL/14$ ./uninstall-postgresql.app/
-bash: ./uninstall-postgresql.app/: is a directory
me#myMac:/Library/PostgreSQL/14$ open ./uninstall-postgresql.app/
LSOpenURLsWithRole() failed with error -10810 for the file /Library/PostgreSQL/14/uninstall-postgresql.app.
me#myMac:/Library/PostgreSQL/14$ open -a ./uninstall-postgresql.app/
Unable to find application named './uninstall-postgresql.app/'
me#myMac:/Library/PostgreSQL/14$ open -a uninstall-postgresql.app/
Unable to find application named 'uninstall-postgresql.app/'
me#myMac:/Library/PostgreSQL/14$ sudo open uninstall-postgresql.app/
Password:
LSOpenURLsWithRole() failed with error -10810 for the file /Library/PostgreSQL/14/uninstall-postgresql.app.
me#myMac:/Library/PostgreSQL/14$ cd /Library/PostgreSQL/14/uninstall-postgresql.app/Contents/MacOS/
me#myMac:/Library/PostgreSQL/14/uninstall-postgresql.app/Contents/MacOS$ install
install install_name_tool installvst
install-info installer
me#myMac:/Library/PostgreSQL/14/uninstall-postgresql.app/Contents/MacOS$ installer
Usage: installer [-help] [-dominfo] [-volinfo] [-pkginfo] [-allowUntrusted] [-dumplog]
[-verbose | -verboseR] [-vers] [-config] [-plist]
[-file <pathToFile>] [-lang <ISOLanguageCode>] [-listiso]
[-showChoicesXML] [-applyChoiceChangesXML <pathToFile>]
[-showChoicesAfterApplyingChangesXML <pathtoFile>]
-pkg <pathToPackage>
-target <[DomainKey|MountPoint]>
me#myMac:/Library/PostgreSQL/14/uninstall-postgresql.app/Contents/MacOS$ installbuilder.sh
-bash: installbuilder.sh: command not found
SINCE I couldn't run/find installbuilder.sh using the following command...
me#myMac:/Library/PostgreSQL/14/uninstall-postgresql.app/Contents/MacOS$ installbuilder.sh
-bash: installbuilder.sh: command not found
...as the other answers in my OP suggest, I went on to try the steps below:
me#myMac:/Library/PostgreSQL/14/uninstall-postgresql.app/Contents/MacOS$ ls -la
total 3112
drwxr-xr-x 5 root daemon 160 Sep 23 10:48 ./
drwxr-xr-x 5 root daemon 160 Sep 23 09:18 ../
-rwxr-xr-x 1 root daemon 673 Sep 23 10:48 installbuilder.sh*
-rwxr-xr-x 1 root daemon 1449456 Sep 23 10:07 osx-x86_64*
-rwxr-xr-x 1 root daemon 135216 Jul 14 11:21 uninstall-postgresql*
me#myMac:/Library/PostgreSQL/14/uninstall-postgresql.app/Contents/MacOS$ ./installbuilder.sh
Unable to initialize installer
me#myMac:/Library/PostgreSQL/14/uninstall-postgresql.app/Contents/MacOS$ ./uninstall-postgresql
Usage: ./uninstall-postgresql installerName [args ...]
me#myMac:/Library/PostgreSQL/14/uninstall-postgresql.app/Contents/MacOS$ ./uninstall-postgresql osx-x86_64
and VOILA!!!
This launched the uninstall GUI
Choose UNINSTALL ALL / REMOVE ENTIRE INSTALLATION
The uninstaller will do its thing and then prompt you with this:
At this point you'll want to follow the steps provided in this PREVIOUS StackOverflow ANSWER - steps 3 through 6 of #user1181328's answer. I'll list them here for convenience:
Remove the PostgreSQL and data folders. The Wizard will notify you that these were not removed.
sudo rm -rf /Library/PostgreSQL
Remove the ini file:
sudo rm /etc/postgres-reg.ini
Remove the PostgreSQL user:
using System Preferences -> Users & Groups.
Unlock the settings panel by clicking on the padlock and entering your password.
Select the PostgreSQL user and click on the minus button.
Restore your shared memory settings:
sudo rm /etc/sysctl.conf
That should be all! The uninstall wizard would have removed all icons and start-up applications files so you don't have to worry about those.

cannot connect to "workspaceMount" at container launch from vscode

using vscode and wsl2, I have tried to launch a container using the default method and no customization. This generated the same error as below.
so following vscode docs I set a "workspaceMount" in devcontainer.json
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/myRepo,type=bind,consistency=delegated",
"workspaceFolder": "/workspaces",
I select Reopen in container, the launch sequence happens but an error is generated
a mount config is invalid, make sure it has the right format and a source folder that exists on the machine where the Docker daemon is running
the log error is
Command failed: docker run -a STDOUT -a STDERR --mount source=d:\git\myRepo,target=/workspaces/myRepo,type=bind,consistency=delegated --mount type=volume,src=vscode,dst=/vscode -l vsch.quality=stable -l vsch.remote.devPort=0 -l vsch.local.folder=d:\git\myRepo --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --entrypoint /bin/sh vsc-myRepo-a878aa9edbcf04f717c76e764dabcde6 -c echo Container started ; trap "exit 0" 15; while sleep 1 & wait $!; do :; done
by launching the container from docker desktop I can confirm
cd /workspaces
ls -l
drwxr-xr-x 2 root root 4096 Dec 3 11:48 myRepo
Is this issue due to owner root:root ?
Should this be changed by chown in the Dokerfile? if so could you provide a sample code to do this, is it by RUN chown ...?
I guess you followed the documentation in https://code.visualstudio.com/docs/remote/containers-advanced
The source should contains the subfolder "myRepo" and the target only "workspaces"
"workspaceMount": "source=${localWorkspaceFolder}/myRepo,target=/workspaces,type=bind,consistency=delegated",
"workspaceFolder": "/workspaces",

scp is giving no such file or directory

The Linux I have in this container is as shown below:
root#sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient# uname -a
Linux sbolla-6c7b7589d8-5c2rb 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 GNU/Linux
root#sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient#
I am trying to do a simple scp with sshpass command as shown below and running into this error. any ideas really appreciated. Please note that I have tried scp and not cp. Infact this line is in a script, I tried it on the linux command line I got this error. I have also tried escaping the Environment variables with ' and " and \ and all combos, but that doesn't seem to have helped.
root#sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient/bin# sshpass -p '$H_PASSWORD' scp -v $H_USERNAME#$H_HOSTNAME:server.pem .
Executing: cp '--' 'admin#abc-def.brilliant.local' '.'
cp: cannot stat 'admin#abc-def.brilliant.local': No such file or directory
Executing: cp '--' ':server.pem' '.'
cp: cannot stat ':server.pem': No such file or directory
root#sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient/bin#
If I explicitly use this command i got it to work, not sure why. Please not that hostname in these outputs have been edited to some goofy names
root#sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient# sshpass -p $HSM_PASSWORD scp admin#grs-defcon.brilliant.local:server.pem .
ls -lia
root#sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient# ls -l | grep ser
-rw-r--r-- 1 root root 1172 Apr 28 12:23 server.pem
root#sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient# date
Sat Apr 28 12:24:29 UTC 2018
root#sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient#
I have tried the answer provided below but didn't work
sshpass -p "$H_PASSWORD" scp -v $H_USERNAME#${H_HOSTNAME}:server.pem .
another thing I have noticed is if I do the env on this container, I see an extra line in the environment variable , could that be an issue. See how this env shows. Note that I have not entered a line on purpose, when I type env command I see line next to the H_HOSTNAME and the H_PARTITION which is weird
H_PARTITION=Operator
MYSQL_PORT=tcp://11.123.113.242:3306
LUNAHS=TRUE
H_HOSTNAME=grs-defcon.brilliant.local
ROOT_PORT_443_TCP_PORT=443
MYSQL_PORT_3306_TCP_ADDR=11.456.231.242
Looks like 2 shell expansion issues. Try:
sshpass -p "$H_PASSWORD" scp -v $H_USERNAME#${H_HOSTNAME}:server.pem .
# sshpass -p '$H_PASSWORD' scp -v $H_USERNAME#$H_HOSTNAME:server.pem .
Executing: cp '--' 'admin#abc-def.brilliant.local' '.'
cp: cannot stat 'admin#abc-def.brilliant.local': No such file or directory
Executing: cp '--' ':server.pem' '.'
Your shell variable H_HOSTNAME has some white space at the end. It's causing the scp command to be something like this:
scp -v someuser#somehost :server.pem .
Scp interprets this to mean that two local files named someuser#somehost and :server.pem should be copied to the local directory .. It's trying to do a local-to-local copy for each file by invoking the cp program.

Run scripts on start or end of xsession

I am trying to find a way to run a script on sleep before an x session ends, because the script requires an active x session to execute properly. Storing the script in /etc/pm/sleep.d did not work (and returned errors related to a non-existent x session). Any ideas where to put the script?
Update in response to comments
king#death-star /etc/acpi $ cat 01_revert_kb_on_sleep
#!/bin/bash
touch ~/Desktop/touchfile_my_script_acpi
case "$1" in
hibernate|suspend)
sh -c "/home/king/Desktop/Scripts/rotate_desktop normal; /home/king/Desktop/Scripts/misc/my_keyboard on" 2> ~/Desktop/revert_kb_error_log.txt ;;
#thaw|resume)
king#death-star /etc/acpi $ ls
total 1MB
drwxr-xr-x 3 root root 1MB Jun 11 23:36 .
drwxr-xr-x 163 root root 1MB Jun 11 23:41 ..
-rwxr-xr-x 1 root root 1MB Jun 11 23:36 01_revert_kb_on_sleep
king#death-star /etc/acpi $ ps -ef| grep acpid
root 1070 1 0 23:41 ? 00:00:00 acpid -c /etc/acpi/events -s /var/run/acpid.socket
king 3499 2574 0 23:52 pts/2 00:00:00 grep --colour=auto acpid
Step 1.
a. Enable and start the acpi service.
b. Run the acpi_listen command and try putting the computer to sleep via various methods (pushing the power button, closing the lid, etc.)
c. Find out what events are triggered, when you do the above. In my case they were: button/lid LID close and button/sleep SBTN 00000080 00000000
Step 2.
a. Create the file /etc/acpi/events/my_events with the following:
event=(button/sleep SBTN|button/lid LID close)
action=/etc/acpi/my_script.sh
Substitute the events in the event= line with your events.
b. Create the file /etc/acpi/my_script.sh with the following:
#!/bin/sh
/home/king/Desktop/Scripts/rotate_desktop normal
/home/king/Desktop/Scripts/misc/my_keyboard on
NB. You might need to add export DISPLAY=:0 before the scripts to get access to your X session.
NB2: Your scripts will run with root user credentials. To run with your user credentials, you might want to do:
sudo -u king /home/king/Desktop/Scripts/rotate_desktop normal
sudo -u king /home/king/Desktop/Scripts/misc/my_keyboard on
c. Make the file /etc/acpi/my_script.sh executable:
chmod +x /etc/acpi/my_script.sh
d. Restart the acpi service.
Step 3. Share and enjoy.

Cannot remove file or Directory

I have root on the server in question.
OS: Solaris 10 sparc
When I ls the audit_old directory I get:
root#z10801 audit_old # ls
qm2_ora_24871_1c.aud.gz
ls -al results in:
root#z10801 audit_old # ls -al
total 250658
drwxr-x--- 2 oraqm2 dba 128261632 Mar 6 21:55 .
drwxr-x--- 17 oraqm2 dba 512 Mar 6 20:55 ..
rm gives me:
root#z10801 audit_old # rm qm2_ora_24871_1c.aud.gz
qm2_ora_24871_1c.aud.gz: No such file or directory
rm -rf the dir gives me:
root#z10801 rdbms # rm -rf audit_old/
rm: Unable to remove directory audit_old/: File exists
Any help would be great!
Thanks!
This behavior may be due to a file currently open by a separate process.
Even though you have removed it, the file is not truly removed by the OS until the process closes the file.
Try to find out the process that has the file open by using:
$ fuser .
In the directory which has the problem.
This command will print the process Id's which have files currently in use.