How to remote control Vagrant installed on Windows, within Linux Subsystem? - windows

According to the documentation of Vagrant, the topic WSL and Vagrant is advanced.
You need to install Vagrant on Linux, because:
While the vagrant.exe executable provided by the Vagrant Windows
installation is accessible from within the WSL, it will not function
as expected.
But I don't want to run Vagrant primarily in Linux. I would like to use Virtual Box, installed on my Windows 10 host. But I don't want to leave Linux bash, just to start Vagrant.
Is there a way to remote control Vagrant from within WSL?

It is true, that $ vagrant.exe would cause unexpected behaviour, because Vagrant (installed on Windows) is unable to handle unix-style paths.
But what actually works:
When you are in bash, enter $ cmd.exe
Perform your Vagrant commands, e.g.: C:\> vagrant up
And return to bash, using C:\> exit
Fortunately cmd.exe has got options, which allows us to call Vagrant via cmd.exe:
$ cmd.exe /c vagrant up
This will launch Windows' command line, perform the command, and return to bash.
Even more cool, when you add this to your ~/.bashrc file:
alias cmd='cmd.exe'
alias vagrant='cmd /c vagrant'
You can use the native vagrant commands in WSL bash (performed in Windows):
$ vagrant up
For me, this works like charm.
Notice: I've changed my root mount paths of harddrives from /mnt/c to /c. When I enter cmd.exe I'll end up in the same directory. Windows does convert the paths. But Windows is not able to handle e.g. ~. Then, Windows will end up in C:\Windows\System32

Related

How with wsl 2 open new ubuntu terminal from command line?

How can i open new ubuntu terminal windows or terminal subtab with terminal command?
I need to execute it from current opened ubuntu terminal
You should have programs from your Windows %PATH% available in your WSL $PATH, so you may be able to just use cmd.exe /c bash or similar
Alternatively, you could install an X server on Windows (like Xming) and run a terminal emulator like konsole or Terminator inside WSL

adb: command not found- Window 10 shell

I am trying to run the adb command using adb shell. Running well on mac but not in the window.
Add the path to the folder containing adb.exe to the PATH environment variable. If you don't have adb.exe in your computer, download one.
(Off topic) Besides, you seems trying to run a Linux shell script on Windows, please use some software like Cygwin or MSYS2.

Start WSL Ubuntu in specific or current folder on Windows

When installing Subsystem for Linux and Ubuntu from store on his development machine I can switch (or start) to Ubuntu shell by simply
But the Ubuntu shell start in /home/techsupp folder by default. Is it possible to force it to start in same folder than the one I use my Ubuntu command?
So in my example I should be in
/mnt/h
Thank you.
What I already tried:
H:\>ubuntu help
Launches or configures a linux distribution.
Usage:
<no args>
- Launches the distro's default behavior. By default, this launches your default shell.
run <command line>
- Run the given command line in that distro, using the default configuration.
- Everything after `run ` is passed to the linux LaunchProcess call.
config [setting [value]]
- Configure certain settings for this distro.
- Settings are any of the following (by default)
- `--default-user <username>`: Set the default user for this distro to <username>
clean
- Uninstalls the distro. The appx remains on your machine. This can be
useful for "factory resetting" your instance. This removes the linux
filesystem from the disk, but not the app from your PC, so you don't
need to redownload the entire tar.gz again.
help
- Print this usage message.
I also discover this request on uservoice: https://wpdev.uservoice.com/forums/266908-command-prompt-console-windows-subsystem-for-l/suggestions/13421103-let-us-right-click-open-bash-here-from-explorer?tracking_code=8a8bc624c72a8336565fcd6d5737d712
Please vote for it.
I'm on Windows 10 Home with May Update and have Ubuntu 18.04 for WSL installed, I can open the console in any folder with Shift + Right Click and selecting the Open Linux shell here option
If you check in Task Manager how the explorer "Open Linux shell here" option opens wsl, you can see that there's a "--cd" option.
ubuntu run
run <command line>
Run the provided command line in the current working directory. If no
command line is provided, the default shell is launched.
As far as I can tell the effect is the same as running ubuntu, except that it starts in the current directory.
This command works even as a right click open here command in explorer. Adapting from this article:
RegEdit to HKEY_CLASSES_ROOT\Directory\Background\shell and create a new key
edit (Default) to "Open Ubuntu here" or similar.
add a key named command
edit (Default) to ubuntu run
Now you have a functional "Open Ubuntu here" right click menu in explorer.
The problem I have with wsl is that the wsl bash window doesn't have the Ubuntu icon, even if it starts the Ubuntu distribution.
If you use wsl.exe, it will start WSL in current directory. But the difference between wsl and ubuntu is that if you have installed two or more distros (e,g, Ubuntu and Fedora), the default one will get started. You can set the default to Ubuntu by running wslconfig /setdefault Ubuntu.
Reference: [1] https://learn.microsoft.com/en-us/windows/wsl/wsl-config
seems that there is a very simpel solution.
just add the following in Ubuntu configuration in the profiles.json file
"commandline": "wsl ~ -d Ubuntu",
The method that has worked for me is to use the Windows Terminal app and configure it to start in the desired location.
Example based on WSL2 and Ubuntu 20.04:
settings.json - Add this line to "Ubuntu-20.04" section:
"startingDirectory": "//wsl$/Ubuntu-20.04/home/<username>/"
Change <username> to be the name of the user you created on install of Ubuntu 20.04.
Step 1: Install Windows Terminal
Step 2: Go to the folder you want to open Ubuntu in and open Windows Terminal by right-clicking.
Step 3: Go to Windows Terminal Settings and navigate to your Linux distro (in my case Ubuntu 20.04) and check this option.
Now every time you open Ubuntu through the Windows terminal it will open in that directory.
Modern solution
Install windows terminal , from Microsoft store
Go on settings
Once you have ubuntu installed you will see it on the list of profiles and then click on open json
Open cmd , type wsl , type cd, type pwdwslc then copy the path [!
And put it in the json file, on ubuntu profile, startingDirectory
Note: I have used linux home directory as default directory used by ubuntu. So if you feel like you have other directory you want to use you can replace it with /home/claranceliberi to your own prefereble directory
with this little script you can execute every command from the directory your Powershell is currently in. It only works if the drive is already mounted to /mnt/ in the subsystem. It doesn't work with network resources.
function tux {$dl = (pwd).Path | wsl eval "cut -c 1 | tr 'A-Z' 'a-z'"; $wd = (pwd).Path | wsl eval "cut -d : -f 2 | tr '\\' '/' 2> /dev/null" ; wsl eval "cd '/mnt/$dl$wd' && eval '$args'"}
after you have executed it, you can use it like this:
tux vim test.txt
First, you have to check whether wsl is using ubuntu as default or not.
For me it was not. Write the below command on cmd:
wsl -l
Like this
If not then Write wsl -s Ubuntu-20.04 to set it as default.
Now you can run ubuntu bash from any directory by doing shift + Rightclick as shown Here.
if your default terminal is Ubuntu, then you can open Ubuntu in the current dir easily.
Go to the address bar of the file explorer by clicking on it
or you can use keyboard shortcut alt+d and
there type
wt -d .
and if the default is Ubuntu, it will open Ubuntu on that path or you can also type
ubuntu run
and it doesn't matter if the default terminal is Ubuntu or not, it will open ubuntu there regardless of anything.

emacs 24 on windows 7, tramp cannot find plink program

I am trying to use Emacs 24.2 with Tramp on windows 7 to remotely edit files on a linux server. I installed the Putty suit program and OpenSSH. I also placed the plink.exe in the putty suit into the bin folder under the emacs 24 folder, and added the folder emacs24/bin into the PATH environment variable.
However, when I try to access the remote file from emacs with the command in the minibuffer: /username#host:filename, I get the following error message from emacs: plink is not recognized as an internal or external command. It seems that emacs cannot find the plink program. But, when I try to run plink in windows cmd, it can find the plink program. Also, I can ssh to the remote server in windows cmd.
Can anyone tell me what's my problem? Do I need to install cygwin to make it work? Thanks a lot.
To get tramp with plink to work, I had to add my PuTTY path to my system search path.
On Windows 10:
control panel >> System & Security >> System >> advanced system settings >> enviroment variables
To PATH I appended the PuTTY path: C:\Program Files (x86)\PuTTY
I'm guessing the key is that from PowerShell or the command prompt, you need to be able to run plink without specifying the path.
I was able to resolve this and I did not have to install cygwin.
Try adding the path where putty was installed to your exec-path variable in emacs. Execute the following elisp code in emacs or put it in your .emacs file. Make sure the slashes are forward, not backslashes, as Emacs and Windows use different conventions.
(add-to-list 'exec-path "C:/Program Files (x86)/PuTTy")
check what exec-path is set to by typing C-h v exec-path

Is it possible to ssh into Windows (through a cygwin sshd) and start a program on a logged in Windows user's desktop?

Is it possible to ssh into Windows (through a cygwin sshd) and start a program on a logged in Windows user's desktop?
Put another way, say a user ABC is logged in on windows and a remote user logs in with ABC's login/password over ssh, can remote ABC pop up an app on the local ABC user's desktop?
I am asking this on Stackoverflow and not Serverfault because the motivation for doing this is programmatic in nature. The remote call will be coming from a Linux box so while it may be possible(?) to do this using WMI or some other approach, ssh seemed like the simplest.
Happy to hear simpler/better alternatives though.
Thanks!
If your cygwin sshd is running under a privileged account, it can get a handle to the current desktop and put windows on it. See the desktop parameter of STARTUPINFO for CreateProcess.
My own solution. Tested on windows XP (but I think it should run in any windows environment with a little effort).
You need to use the psexec and quser command.
First, put psexec and quser in a directory included in the cygwin's PATH environment variable. Just copy these files into the bin directory under cygwin.
You can find the quser.exe in your %system32%\dllcache dir. But for any reason I can't access to it (or access to the mentioned directory) through cygwin commands (i.e. ls, cp, etc), so I made a copy using the microsoft's copy command to the cygwin\bin folder.
Notes: I think it's helpful to have the suite psutils all in the bin folder of cygwin. The first time you run either of these utilities will have to accept a license agreement from Microsoft warning, so run psexec from Windows explorer the first time.
Then create these alias in your .bash_profile file:
alias winrun='psexec \\\\YOU_USERNAME_HERE -d -i `quser | grep YOU_USERNAME_HERE | grep console | awk "{print \\\$3}"`'
alias explorethis='winrun explorer $(cygpath -w `pwd`)'
Remember that you will need to translate the current directory using cygpath if you need to pass it as argument of a command ("explorethis" is an example of that).

Resources