Need an applescript (which I haven't used before) to deploy our VPN connection settings on our remote workers mac boxes. this is for PPTP VPN.
Upon googling I came across the following link :
http://discussions.apple.com/thread.jspa?messageID=10368307
But still I can't :
a) seem to name the VPN connection
b) give it a pptp vpn server address
c) give dns, default gateway and any custom routes for this vpn to work.
How can I add those fields / enteries in ?
tell application “System Preferences”
reveal pane “Network”
activate
tell application “System Events”
tell process “System Preferences”
tell window 1
click button “Add Service”
tell sheet 1
click pop up button 1
click menu item “VPN” of menu 1 of pop up button 1
delay 1
click pop up button 2
click menu item “PPTP” of menu 1 of pop up button 2
click button “Create”
end tell
click button “Apply”
end tell
end tell
delay 1 — optional (just for visual feedback)
keystroke “w” using {command down}
end tell
end tell
The above script seems to create the connection just fine but without the details - and I am not sure about what syntax I would use to get this going.
Thanks for your input!
Regards
Thanks
Rihatum, here's the full Applescript with all the things you want to do.
--create new VPN PPTP service on the ethernet interface
do shell script "networksetup -createnetworkservice \"VPN (PPTP)\" en0 - where en0" with administrator privileges
--set the IP, subnet, & router IP ( order = ip subnet route )
do shell script "networksetup -setmanual \"VPN (PPTP)\" 192.168.2.50 255.255.255.0 192.168.2.1" with administrator privileges
--set VPN service using DHCP -- if using DHCP don't use manual setting above
do shell script "networksetup -setdhcp \"VPN (PPTP)\"" with administrator privileges
--set DNS
do shell script "networksetup -setdnsservers \"VPN (PPTP)\" 208.67.222.222" with administrator privileges
--set search domain
do shell script "networksetup -setsearchdomains \"VPN (PPTP)\" my_company_domain.com" with administrator privileges
--rename network service -- replace CISCO_VPN with your preferred name
do shell script "networksetup -renamenetworkservice \"VPN (PPTP)\" CISCO_VPN" with administrator privileges
I think what you want to do is build a script using the networksetup command
and use a series of "do shell script" lines in your AppleScript instead of trying to GUI script the configuration.
Fo example, in your AppleScript this command will create a new VPN PPTP connection on the ethernet interface:
do shell script "networksetup -createnetworkservice \"VPN (PPTP)\" en0 -where en0" with administrator privileges
To set the IP, subnet, & router IPs you would use this:
( -setmanual networkservice ip subnet router )
do shell script "networksetup -setmanual \"VPN (PPTP)\" 192.168.2.50 255.255.255.0 192.168.2.1" with administrator privileges
After that you can use the other options to configure the rest. For example,
to add a DNS IP to your newly created VPN PPTP connection you would add this to your AppleScript:
do shell script "networksetup -setdnsservers \"VPN (PPTP)\" 208.67.222.222" with administrator privileges
Check out the man page for the networksetup command. It does a tremendous amount of things. Also, you can Google that command and you will find a lot of forums with people discussing Mac command line network configurations. The single keyword networksetup doesn't work too well because it returns a lot of Windows pages so Google for "sudo networksetup" and that will return Mac related pages.
I tried the solution using the networksetup tool, but it didn't work for me :S I actually came up with a successful script using UI automation. It put up a post about it here: http://blog.affirmix.com/2011/01/12/how-to-configure-a-vpn-in-mac-os-x-usingapplescript/
Related
I have a Centos VM on Google Cloud, I am using a custom SSH port and private SSH file to manage my VM.It worked fine for a long time but yesterday I started the "FirewallD" service in CentOS but I forgot to add a rule to allow my custom SSH port.
Now I can't connect to my VM through SSH, I also have tried to connect my VM through Web Console ("Open in browser window on custom port" and Open in browser window using provided private SSH key),neither of them works.
Are there any other solutions?
If you don’t have access through ssh at your vm, you could use the serial port to login
Go to the VM instances page in Google Cloud Platform console.
Click on the instance for which you want to add a startup script.
Click the Edit button at the top of the page.
Click on ‘Enable connecting to serial ports’
Click Save and then click RESET on the top of the page. You might need to wait for some time for the instance to reboot.
Click on 'Connect to serial port' in the page.
If you don’t have a root password for the serial console, you could use a startup script to add it to your instance, the script would be like this:
Go to the VM instances page in Google Cloud Platform console.
Click on the instance for which you want to add a startup script.
Click the Edit button at the top of the page.
Click on ‘Enable connecting to serial ports’
Under Custom metadata, click Add item.
Set 'Key' to 'startup-script' and set 'Value' to this script:
#! /bin/bash
useradd -G <an existing group in the instance> USERNAME
echo USERNAME:PASSWORD | chpasswd
Click Save and then click RESET on the top of the page. You might need to wait for some time for the instance to reboot.
Click on 'Connect to serial port' in the page.
In the new window, you might need to wait a bit and press on Enter of your keyboard once; then, you should see the login prompt.
Login using the USERNAME and PASSWORD you provided.
In this way you can login at the vm and stop the firewall service to modify your rules before to start the service again
I connect to a server within Visual Studio Code using SSH ("Remote-SSH: Connect to Host..."). When working in the terminal within VS Code, the command code <file> results in opening the file in VS Code of the client (therefore on my screen). Now let's suppose I establish another SSH connection from the current session to a workstation within the network of the server using ssh <some workstation>. When I now try to open a file in VS Code using code <file>, nothing happens.
My questions are:
Since the last code <file> mentioned didn't open anything on my screen, is it possible that VS Code did open on any other screen connected to either the server or the workstation?
Is there any possibility to open the file within my VS Code?
As for your first question:
There's is NO WAY your action could have opened a window on any other screen than yours. For that to happen you'd have to "link" your ssh session to that screen, which would require a bunch of intermediary steps.
Now for the second question:
Yes its possible (and pretty easy). BUT you will have to open another session of VScode that will connect to the "workstation" through the server.
Currently, to connect to the server, you probably had to add these lines to your ssh config file:
Host MyServer
HostName adress.server
User username
To open a session in the workstation, through the server, you should add these lines:
Host MyWorkstation
HostName workstation.adress.within.network.of.the.server
User usernameInWorkstation
ProxyJump server.adress
Using the Google Developer Console "Compute Engine" I am trying to connect to a Google VM instance via SSH.
It doesn't work. I had trouble creating the instance to begin with due to a problem with the "network association".
Here was my question and solution for that: Why is "Create" disabled in Google Compute Engine VM instances?
What are the likely causes for my SSH issue now?
It turned out to be a firewall issue. Unlike the "default" network, when you add one manually, it doesn't automatically open port 22 for ssh to work.
The easiest way to fix this is via the Google Developer Console "Networking" page. If you go to the networks section and select the custom network you are using, it has the option to add firewall rules. Unfortunately for me, I didn't figure this out until I did it with the Google Cloud Shell... Here's how I did it the "long way", which will in fact give you more control and insight into this whole Google VM management model. It will also ensure you can connect via the Google Cloud Shell in case you need to again in the future:
In the "Compute Engine" go to the VM section and select your VM. In the top left corner of the screen is an "SSH" button and an ellipsis ("...") button. Click the "..." and select "View gcloud command". When that window opens, copy the command to the clipboard. Then close the window and click the ">_" (Activate Google Cloud Shell) button in the upper right corner of the screen.
When the shell loads, paste in the command (with Ctrl+V). After attempting to connect, it will eventually time out if you have this firewall problem going on.
To display the firewall rules on the network you are using enter the following:
gcloud compute firewall-rules list
To inspect a rule in more detail use this:
gcloud compute firewall-rules describe [rule name]
Check for a rule with a suffix of "allow-ssh", or more specifically one that opens up port 22. It is probably missing.
If you were in fact on the "default" network, you could use the command you'll find in the Google documentation for this:
gcloud compute firewall-rules create default-allow-ssh --allow tcp:22
But, if you are on an alternate network, use this more explicit command:
gcloud compute firewall-rules create [network name]-allow-ssh --allow tcp:22 --network [network name] --source-ranges 0.0.0.0/0 --description "Allow SSH from anywhere."
Replace [network name] with your literal value.
After executing that, try the connection command again. It ought to work now!
I have restarted our google cloud compute engine instance, however after the restart ssh is no longer working and giving connection refused.
I have verified and the ssh keys are configured for the users, and firewall rules are open for ssh.
Is there any other method I can use to try and resolve this?
The first thing to do is to check the Serial console output of the machine to determine if the SSH daemon has started or not. That log can be accessed from the Developer Console.
If you couldn't ssh to the instance you can follow the below step to access the instance from the serial console:
Connect to the instance using the serial console
1. Go to the VM instances page in Google Cloud Platform console.
2. Click on the instance for which you want to add a startup script.
3. Click the Edit button at the top of the page.
4. Click on ‘Enable connecting to serial ports’
5. Under Custom metadata, click Add item.
6. Set 'Key' to 'startup-script' and set 'Value' to this script:
#! /bin/bash
useradd -G sudo USERNAME
echo 'USERNAME:PASSWORD' | chpasswd
7. Click Save and then click RESET on the top of the page. You might need to wait for some time for the instance to reboot.
8. Click on 'Connect to serial port' in the page.
9. In the new window, you might need to wait a bit and press on Enter of your keyboard once; then, you should see the login prompt.
10. Login using the USERNAME and PASSWORD you provided.
I'm writing a script that periodically checks that certain services are running on remote workstations. I'm having a devil of a time getting an "SC \workst1 query" command working from one test machine to another. Both machines are running XP pro SP3. Neither is part of a domain. Both are in the same workgroup, and the administrator accounts have the same passwords.
I keep getting the "[SC] OpenSCManager FAILED 5: Access is denied" message, from either workstation to the other. I have tried using elevated privileges on both. Windows firewall software is turned off. There are no messages are showing up in the Event security logs. When (as administrator) I try going to "Computer Management" -> "connect to another computer" and access the remote services I get "Error 5 Access is denied".
I can set up a filesystem share between the two machines successfully, and "net use \workst1\IPC$ /user:Administrator" completes successfully, but the SC query still fails. I'm using IP addresses and not hostnames in these commands, but that doesn't help. I don't know what else to try. Thanks for the help.
Try to run the commans as a Administrator
start-> (type cmd in search box), right click on cmd, Run as a administrator -> execute your command
You must have administrative rights on the remote machine.
Moreover you must access the drive before calling "sc".
This can be achieved in command line using
net use \\remotemachine\admin$ <password> /user:<username>
admin$ is a hidden shared drive accessible to administrators that "sc" uses to control services.
I was having the same issue today trying to check if a service is enabled remotely.
I could solve the issue modifying the User Account Control for remote restrictions in windows:
To disable UAC remote restrictions, follow these steps:
Click Start, click Run, type regedit, and then press ENTER.
Locate and then click the following registry subkey: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
If the LocalAccountTokenFilterPolicy registry entry does not exist,
follow these steps:
On the Edit menu, point to New, and then click DWORD Value. Type LocalAccountTokenFilterPolicy, and then press ENTER.
Right-click LocalAccountTokenFilterPolicy, and then click Modify. In the Value data box, type 1, and then click OK.
Exit Registry Editor.
More information about this solution in this site.
Your user should be remote, from Manage and Local users and groups
The UAC issue is obvious you have to pull down the lever for UAC setting
Also while installing the services you can use the following command
SC create SERVICENAME DisplayName= "DISPLAYNAME" binPath= "PATH OF EXE" start= disabled type= share