Why does vagrant ssh'ing always re-ask me for my ssh executable? - windows

Using Vagrant under Windows 7, trying to ssh into my VM. If I open cmd and run vagrant ssh, I am given the response:
ssh exectuable not found in any directories in the %PATH% variable, Is an SSH client installed? Try installing Cygwin, MinGW, or Git, all of which contain an SSH client. Or use your favorite SSH client with the following authentication...
So I add Git to my PATH variable:
set PATH=%PATH%;C:\Program Files (x86)\Git\bin
And I confirm my PATH variable now contains this:
<snip>C:\ProgramData\ComposerSetup\bin;C:\Program Files\cURL\bin;"C:\Program Files (x86)\Git\bin";"C:\Program Files (x86)\Git\cmd";C:\Program Files\nodejs\;C:\HashiCorp\Vagrant\bin
So, I run vagrant ssh again, and it works:
vagrant ssh
Welcome to Ubuntu...
vagrant#mywebsite:~$
But, if I now close my cmd window and reopen it, I can no longer call vagrant ssh. I'm given the same notice I was initially given about not having an SSH client in my PATH variable. What this means is that essentially, I am being re-asked every time to provide an SSH client.
Why?

You have set the variable only for the current command session - you need to set as environment variable
For windows 7
From the Desktop, right-click the Computer icon and select Properties. If you don't have a Computer icon on your desktop, click the Start button, right-click the Computer option in the Start menu, and select Properties.
Click the Advanced System Settings link in the left column.
In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
In the Environment Variables window (pictured below), highlight the Path variable in the "System variables" section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon as shown below. You will end up with something similar as
C:\ProgramData\ComposerSetup\bin;C:\Program Files\cURL\bin;"C:\Program Files (x86)\Git\bin";"C:\Program Files (x86)\Git\cmd";C:\Program Files\nodejs\;C:\HashiCorp\Vagrant\bin

Related

To open a folder in Terminal

Is there any option to open the program files in Terminal(windows) directly from the folder's location in the drive, without actually typing all the commands to navigate and then executing it.
I guess "open in Terminal" option in present in Ubuntu;
You can achieve this in a number of ways.
Click on File at the top left corner of the current folder location. You will see Open Windows PowerShell option. Click on any option. It will open Power Shell and automatically navigate to the current folder.
Another option, Press Shift and Right Click. It will show Open PowerShell window here option.
If you are looking for Ubuntu-like terminal(bash) then you can install the Git terminal from here. Then, on right-click you will see Git Bash Here option.

Permanently Change Environment Variables in Windows

I found a way to change the default home directory of a user but I am having trouble with it.
Doing this will change the home drive to C:
But then when I check the environment variable:
It is still H:, with a system restart the Enviroment variables in windows settings will also return to H:/
I have also tried changing it like this:
Which appears to work but if i open a new cmd it will have reverted back to H:/
Now I am trying to do this so that OpenSSH will recognise C as my home directory instead of H: which is a network drive, forcing OpenSSH not to work unless I cam connected to my university network via VPN.
What can I do to set this permanently and in the eyes of OpenSSH?
Nowhere does it mention a dependency between the HOMEDRIVE value and the HOMEDIRECTORY value, what was happening (I think) is that it was failing to map the home directory to the HOMEDRIVE and therefore defaulting back to a safe value (C:)
I wrote a script to update the local AD, replace the values in [] with your values. Copy and paste into a .vbs file and double click on it to run it.
Set objUser = GetObject("WinNT://[COMPUTERNAME]/[USERNAME],user")
objUser.homeDirDrive = "H:"
objUser.HomeDirectory = "[URNPATH]"
objUser.SetInfo
e.g.
Set objUser = GetObject("WinNT://UQBDART-2328/BEN,user")
objUser.homeDirDrive = "H:"
objUser.HomeDirectory = "\\SERVER\SHARE"
objUser.SetInfo
run this, reboot and test. It worked for me.
Sounds like the AD profile on the domain is overwriting the user defined variables. I see your screenshot says you are connected to the eait.org.edu.au domain. That will be the root of your issue. Just to include some details here that I spotted elsewhere, that may be of help to you:
HOMEDRIVE, HOMEPATH & HOMESHARE are set and updated via Active Directory. HOMEDRIVE & HOMEPATH are set even without a home drive set on the account; however they will be overridden by any user account properties set in AD.
Also see these KB articles:
http://support.microsoft.com/kb/841343
http://support.microsoft.com/kb/237566
http://support.microsoft.com/kb/101507
On a side-note for another way around the issue:
-I have in the past created a new instance of the windows command-line shell executable that automatically runs a custom script, so everytime you launch the shell, the environment variable could be overriden.
-To do that you could just put the code you posted to change the environment variable into a batch script, stored wherever you like, then edit the shortcut(s) used to launch the shell by going to properties > then alter the Target box: %SystemRoot%\system32\cmd.exe /K "C:\Documents and Settings\Administrator\My Documents\customshellscript.cmd" (Obviously the part of the path after /K is the location of your custom script)
This way, if you are using openSSH over the console anyway, it will always have the homedrive set correctly.
Changing those environment variable's values is not "supported", at least it will not work as you expect because Windows changes them back.
According to this Microsoft knowledge base article (KB841343), you should use policies, if you need to change these settings. The article also contains links for how to do that (but personally, I never tried). Note that the article was originally written for Windows 2000, but I would strongly suspect, that it is still valid for current Windows versions.
Back in the days of DOS the environment variables were part of the Program Segement which meant that you basically got a local snapshop of the variables limited to the scope of that program.
I'm guessing Windows hasn't changed this and the environment variables available to the CMD window only have the scope of that window and any further windows it spawns. This is supported by this little experiment:
in a CMD window type
set homedrive=h:\
and then test it's updated by typing
set h
from this same window type
start cmd
and in this new window type
set h
when I've done this I get HOMEDRIVE=H:\
if I then just open a new CMD window from the start menu and do the same SET H I get HOMEDRIVE=C:\
I don't know anything about OpenSSH but I suspect like the START CMD got the updated HOMEDRIVE environment variable, if you write a batch to update the environment variable and then execute OpenSSH that'll work.
I had a similar issue, the HOMEDRIVE variable was set to U: which was a drive we no longer used. This was just for one particular user. I went to that user's profile in AD and clicked the Attribute Editor tab. There was an attribute for HOMEDRIVE which I changed from U: to C: - when the user logged in again, it was set correctly. I also updated the HomeDirectory attribute here.
This issue had been really frustrating me trying to find a solution, but I have found what I think is the definitive answer and posted it at:
https://stackoverflow.com/a/60235759/12903197
You need to run 'net user USERNAME /homedir:PATH' where USERNAME is the name of the user you are trying to change and PATH is the drive letter and full path to the desired home folder, which must already exist.
On windows 8:
Hit "windows key".
type "system environment variables".
Allow "Advance system settings" to make changes.
Select "Advance" tab.
Click on "Enviroment Variables...".
Double click on "Path" from "User variable for XXXXXXXX"
Add at the end the variable the new path that you want separated by semicolon.
e.g. C:\Program Files\;C:\Python27\
shareeditdelete (1)flag

iTerm 2 profiles

I have recently switched over to iTerm2 and love it. I am wondering though if there is a way to use profiles to correspond to what environment/specific machine you are on.
Say if I am doing tasks in one window on my mac the profile is displayed as default, but if I ssh into a machine (lets say dev0), the profile on iTerm will update to profile dev0. Once I've finished with dev0 and call exit, the profile will switch to default again.
I realize one work around is to open up a specific profile whenever I want to ssh into another machine and have a way to distinguish, but if the connection is closed it requires you to notice based off text rather than say the background of the window.
Is this possible? If not how can this feature be added, and is there a way I can contribute?
iTerm2 supports a custom escape code that changes the profile on the fly. Put it in your .bashrc or .bash_profile.
<esc>]50;SetProfile=X^G
where X is the profile. For instance, to change the profile to one called "Foo", us this shell script:
#!/bin/bash
echo -e "\033]50;SetProfile=Foo\a"
To change it back when you log out, put code to change the profile back to default in ~/.bash_logout.
for zsh users
lets say you have 2 profiles, one named mac (for your primary machine) and one for linux (your remote machine)
when entering the session, we need to tell zsh to load our profile
connect to remote linux
in ~/.zshrc add echo -e "\033]50;SetProfile=linux\a"
source your files for immediate effect: source ~/.zshrc
your new theme should be visible within the iterm session.
when exiting the session, we need to tell zsh to switch back to our original profile
connect to remote linux
in linux ~/.zlogout add the following
if [ "$SHLVL" = 1 ]; then
echo -e "\033]50;SetProfile=mac\a"
clear
fi
now you can swap profiles with ease <3.
if you are using bash, i believe the steps are similar but you would instead modify ~/.bashrc and ~/.bash_logout
demo
The latest iTerm2 nightly (Build 2.9.20150329-nightly at the time of writing) allows you to do that easily. You can download it here.
Once you've installed and opened it:
Log in to your remote machine via ssh and click iTerm2 (the app menu) > Install Shell Integration. It will download a script with curl and install it. Do the same on your local machine.
Go to Preferences > Profiles.
Create a new profile for your local machine. Customize it to fit your needs (change background color, name, etc)
Go to the Advanced tab and scroll to the bottom.
In Automatic Profile Switching, click '+' and add the hostname of your local machine. The hostname is the one you get when running echo $HOST on the target machine. It is not always the one you see in your prompt.
Create another profile, this time for your remote machine, and customize it.
Add the hostname of the remote machine in Automatic Profile Switching.
Now, if you ssh into the remote machine, your profile will change, and if you exit out of the ssh session, you will be back to your local profile.
You can combine this solution with #esod's answer seamlessly.
Note: it didn't work for me until I created a profile specifically for the desktop instead of using the default profile.
See the documentation for more info.
step 1:
custom your iterm profile, e.g. dark, light
step 2:
add code before to your shell profile, e.g .bashrc or .zshrc
# Change iterm2 profile. Usage it2prof ProfileName (case sensitive)
it2prof() { echo -e "\033]50;SetProfile=$1\a" }
step 3:
make sense your profile
exec $SHELL -l
step 4:
toggle your iterm theme profile
it2prof dark
it2prof light
I had this same wish and found this can be accomplished in iTerm 2 (Build 1.0.0.20130319) in the application's preferences.
You can assign a profile (say a remote profile) with a different preset than your default preset by going to:
Profiles -> Open Profiles
select the profile and click Edit Profiles...
Go to the Colors Tab and choose a preset for this profile from the list in Load Presets...
Further, I've set up Keys shortcut for different profiles so I can have one iTerm window look different than another window. I did this by:
Creating a new a Profile in Preferences
Creating a new Profile Shortcut Key in Preferences-> Keys whose action is New Window with Profile
My Default profile has a black background but sometimes it helps me to have a white background. I duplicate my Default profile and name the new profile DefaultLight. On my Default profile I go to the Keys tab where I create a new Profile Shortcut Key whose Keyboard Shortcut is ^+cmd+n, whose action is New Window with Profile, and whose Profile is DefaultLight.
After saving the prefrences, cmd+n opens a new window with a black background and ^+cmd+n opens a new window with a white background.
There's also a New Tab with Profile action in the Keyboard Shortcut Keys Preference if you're interested in taking this even further.
In my case, I need to combine Yohaï Berreby's answer with my hosts' setting to implement this feature.
In Automatic Profile Switching, click '+' and add the hostname of your local machine. The hostname is the one you get when running echo $HOST on the target machine. It is not always the one you see in your prompt.
My staging server doesn't set $HOST and host name is :
[devel#alveo-staging ~]$ hostname
alveo-staging
But I can't set the rule with hostname as alveo-staging. Because in fact alveo-staging is just an alias of the real hostname (alveo-staging.xxx), which can be set in /etc/hosts.
So the quick solution to this is to use * wildcards, to set the rule as *staging*.
Then it works.
For Fishell user:
1. Create a fish function:
functions it2prof > ~/.config/fish/functions/it2prof.fish
Add this content to ~/.config/fish/functions/it2prof.fish file and save:
function it2prof
echo -e "\033]50;SetProfile=$argv\a"
end
enjoy your command:
it2prof whatever_profile_you_define

How to change cscript.exe to wscript.exe execution for all VBScript files?

After installing the new server, I am facing an issue.
I have lot of .vbs files, all need to run in wscript, reason, I use all those command like WScript.Echo "hello"
I want to be able to see the output when I double click the VBScript file.
But when I right click on the vbs file, I see console, I want to change the default to Windows host, globally!
How can I do that?
You can change the default scripting host to wscript.exe like so:
wscript.exe //H:wscript
If you wish to set cscript as the default host, that works in the same way:
wscript.exe //H:cscript
You can execute cscript.exe with the same arguments for the same result.
You can switch the default script engine with:
wscript //H:Wscript
Good luck!
I was able to solve it by using the following steps:
selecting the VBScript file that I want to open,
right click to select default program for this,
browse to C:/windows/windows32/wscript.exe, and select this.
In command prompt (as administrator):
To set windows script host as default script host enter:
wscript.exe //H:WScript
To set command line based script host as default script host enter:
cscript.exe //H:cscript
Check the Windows Explorer settings for the filetype *.vbs (something like tools->options->file types etc.) and change the "open with" setting to cscript.
Edit: I now advise caution with the recommendations I give below. After continuing to toggle and test my settings, I find I am unable to re-establish cscript as my default script host. (Note that I also retried the procedures given by other answers to this question.)
In addition, I tried using Process Monitor (a.k.a., "ProcMon") to find the reason for my difficulties, but unfortunately have not been unsuccessful.
Finally, I also considered going back to an earlier Windows 7 restore point, but this was complicated by the fact that I just yesterday changed my domain password. So, for now, I'm going to have to put my investigation to rest as other tasks are pressing.
On last thought...I have also considered the possibility that there are network policy security settings that are thwarting my efforts.
Original Answer: Enter the following line in a Windows batch file:
ftype VBSFile="%%SystemRoot%%\System32\WScript.exe" "%%1" %%*
Then, run a Command Prompt as an Administrator and run the batch file.
I believe the above will make the change for all users on the system. To make the change for only the logged in user, do the following (on Windows 7):
Control Panel => Programs => Default Programs => Associate a file type or protocol with a program
Then, in the Name column, scroll down to .vbs and click Change program... in the upper right. Then choose one of the Recommended Programs. If you do not see Microsoft ® Windows Based Script Host, browse to the following file:
C:\Windows\System32\wscript.exe
The guy above who right-clicked to choose the default program was right, however the path should be: C:\Windows\System32\wscript.exe

How to write a script/batch file on windows?

I am using a machine where I do not have administrator privileges and I need to set the e.g. JAVA_HOME each time I boot.
Thus, I'd like to write a script that sets the desired classpath automatically.
How do I do this?
You surely can set the environment variables with a batch file each time you need them, but bear in mind that this will only work for the current process (i. e. the cmd instance you're invoking the batch from) and processes spawned from there. I think you'd rather want persistent environment variables.
Now, in the UNIX world you'd just put them into your shell startup script. In Windows ... not exactly that way.
Right click on "My Computer", select "Properties".
There, go to the "Advanced" tab
Click the button labeled "Environment variables"
You can set JAVA_HOME and GRAILS_HOME under "User variables" there.
You would only need administrator access for changing the system environment variables.
You would want a file with .bat extension for Windows.
SET JAVA_HOME=path
SET GRAILS_HOME=path
On Windows, you could write a .BAT file (BATch), and then simply double-click it each time you log in. a .BAT file is simply a plain text file filled with any commands you would normally issue at the command prompt, e.g.:
cd c:\Temp
c:
set PATH=%PATH%;c:\Program Files\Some Directory\Some Subdirectory
You can optionally precede each line with the # symbol to stop it being echoed to the command window when it executes.
Try calling the following :
SETX JAVA_HOME path
SETX GRAILS_HOME path
If you're allowed they will be set in your profile and you won't need to run them again hopefully. Other wise you'll need to follow #Android's answer

Resources