How can I access to individual sites via SSH? - In order to use WP-CLI
You can SSH in by right-clicking on the site in the sidebar then going to Open Site SSH
After doing that you can immediately use wp
without changing directories.
Perfect. Thank you.
Guess this is a FAQ question, @clay how can I access a site using ssh, but not using the Local application, ie not right-clicking the site but doing: ssh root@mysite.dev
what’s the username and password I should use ?
+1 Need to ssh into - whats the password?
There appears to be no password. Local runs its wordpress components in docker containers, and makes a script for each container that does “docker exec -it [docker-container-id] /bin/bash” to allow you to execute commands on them.
5 posts were split to a new topic: Running PHPUnit in PhpStorm with Local
Learned how to log into the Local machine:
ssh -i ~/.docker/machine/machines/local-by-flywheel/id_rsa docker@192.168.94.100
You’ll find the IP-address in Local->Database dashboard
Edit after re-reading the thread…
Anyone recommend a SSH for Win10?
Thanks.
Hi @mitchrosefelt,
Can you please explain what you’re trying to do?
If you right-click on the site in Local’s sidebar then go to “Open Site SSH” it should open it up in Cmd automatically.
right click to get ssh only works if your default shell is bash. (if you are using fish it doesn’t work)
wp-cli offers a global parameter –ssh= what do I write after that to gain access for wp-cli in my shell to a site on Local?
--ssh=[<scheme>:][<user>@]<host\|container>[:<port>][<path>]
Perform operation against a remote server over SSH
(or a container using scheme of “docker”, “docker-compose”, “vagrant”).
Hey guys, the reason there isn’t a straightforward answer to give is that these are all Docker containers, but we don’t have you install Docker on the host machine such that it is accessible to your $PATH
.
You can tease out what exactly is happening when you are right-clicking and "Open Site SSH"ing by opening the file that is reported in the terminal.
Here’s a screenshot of two terminals I have open, one from clicking Open Site SSH, and one where I open the bash script that the first terminal executed:
Since this is a bash script, that’s why right-clicking within Local won’t work with Fish – this is just a bash script.
When I open that script, there are instructions for connecting to the site’s specific Docker machine:
export DISABLE_AUTO_TITLE="true"
echo -n -e "\033]0;newblank SSH\007"
eval $("/Users/benjamin/Applications/Local by Flywheel.app/Contents/Resources/extraResources/virtual-machine/vendor/docker/osx/docker-machine" env local-by-flywheel);
"/Users/benjamin/Applications/Local by Flywheel.app/Contents/Resources/extraResources/virtual-machine/vendor/docker/osx/docker" exec -it d78472ef6d4f9a4dd1dda96c7a41f94bffad69c60435ec5dff8f0461a379ce09 /bin/bash;
You can break this down into something more easy to understand:
eval $('...' env local-by-flywheel);
This line sets up the terminal session to use the Docker environment that’s running within the local-by-flywheel
VM.
".../docker" exec -it <container_id> /bin/bash;
This line is using the environment we set up in the previous line to create an interactive, teletype terminal running bash.
To your specific question @crs1138 – I haven’t tried this, but you might be able to install Docker so that it’s accessible to your $PATH
and then execute commands directly against the container hash found in that bash file.
I think that it would look something like:
- Install Docker:
brew cask install docker
- Ensure the Local VM is running, and then make Docker use that environment:
eval $(docker-machine env local-by-flywheel)
- Docker commands – for example
docker ps
to list the running containers.
If you try this out, let me know what you find!
– Ben
Hi Ben, this is is what I got…
eval $(docker-machine env local-by-flywheel)
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e9cb6d4b4a08 flywheel:1.1 "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp youthful_pare
2db760ae1612 custom:1.2 "/etc/scripts/sleep.…" 5 weeks ago Up 2 minutes 0.0.0.0:4008->80/tcp, 0.0.0.0:4009->443/tcp, 0.0.0.0:4011->1080/tcp, 0.0.0.0:4010->3306/tcp trusting_lovelace
2ec093e05eae custom:1.2 "/etc/scripts/sleep.…" 8 weeks ago Up 2 minutes 0.0.0.0:4012->80/tcp, 0.0.0.0:4013->443/tcp, 0.0.0.0:4015->1080/tcp, 0.0.0.0:4014->3306/tcp naughty_jackson
WTF is naughty_jackson or trusting_lovelace?
Haha, those are some interesting ones!
Now that you have the container IDs, you can “SSH” into the first one using the custom:1.2
image by running docker exec -it 2db760ae1612 /bin/bash
.
How do I use that with the wp-cli --ssh=
flag?
Great @crs1138 – after you setup the environment for the terminal session:
eval $(docker-machine env local-by-flywheel)
You should be able to reference the naughty_jackson site using that container id:
wp post list --ssh='docker:2ec093e05eae' --allow-root
You’ll need the --allow-root
part since within the container, the processes are being executed as root.
It still gets odd with file permissions and such, but that should be enough for you to be dangerous
Trying to work out how to set up serveo.net to ssh into the docker container -
something like
ssh -R ~/.docker/machine/machines/local-by-flywheel/id_rsa docker@192.168.95.100 serveo.net
any clues?
Trying to use serveo.net + autossh to create more persistent tunnel addresses than ngrok.io, collaborators are sick of tunnel addresses changing each time reboot.
It’s a bummer. This used to work for me some of the time, and now it doesn’t work anymore. I’ve used the long method of connecting that ben.turner provided, which I appreciate, but it seems like this just hasn’t been a reliable function of Local for quite some time. It’s a very important feature, too.
Can this please get some attention from Flywheel?
After doing some digging, I think I found where the problem is happening. Hopefully this will help the Local team to fix the issue, and others to throw together a workaround much easier than described above.
When you right-click on a site and go to “Open Site SSH” it opens your terminal and runs a command. If you’re like me, the command closes prematurely. If you’re in iTerm it throws and error and closes the tab. If you use Terminal, it will leave it open and state that it’s closed.
The line to look out for here is something like the following:
/Users/jason/Library/Application\ Support/Local\ by\ Flywheel/ssh-entry/r1uSme9kV.sh; exit;
The ssh-entry
directory contains a bunch of bash scripts for the respective sites. Each script does all the heavy lifting to identify the site’s container and connect to it via docker. In my case, the site I’m trying to connect to is r1uSme9kV.sh
.
What’s odd here is that the script is immediately followed by exit;
. It seems like the bash script runs asynchronously (or is using asynchronous command). If the docker connection isn’t made in time, the exit;
command runs and closes the shell. If it happens to work fast enough, it connects.
So if you execute the file directly, without the exit;
command, it works great! In my case, I made a ssh-local-container.sh
file in my project that has only the following:
/Users/jason/Library/Application\ Support/Local\ by\ Flywheel/ssh-entry/r1uSme9kV.sh
And just like that, it connects every time.
I suppose the big question for the Local team is why they included the exit;
command after executing the bash script? Omitting that seems to resolve the issue, and if connecting to docker works then it ignores the command.
Hope this helps!