Working on remote server - ssh

My OS: Windows 8
Virtualbox guest: Ubuntu 12.10 server
I configured apache server on vbox guest and mapped http, https, ssh port successfully into ubuntu server. It works nice without any problem.
I tried several IDEs like PHPStorm, Netbeans, editors like Sublime, all they do is to copy whole project from server, edit on local machine then sync back.
But it is not what I need. I want to work directly on guest server using ssh/sftp connection. I know that notepad++ has this functionality but I love sublime look and feel.
Is there any way to work on guest server with sublime or any other ide for free? (There is sftp solution but it's paid and works just like other ide's, not directly on guest machine) Any suggestions?

There are two approaches you can choose from, you will probably select the second one:
Use the KDE desktop environment (yes, it also exists for MS Windows). It features so called 'kio-slaves' which allow to use any protocol out there as if you were doing local file system operations. That means when using a KDE editor like 'kate' or even a whole IDE like 'kdevelop4' you can simply say "open file/project" and not only choose a local file, but something like sftp://server/path/file and start working. The network stuff is handled transparently by the environment, it is fully network transparent. This is how systems should be like. I think the GNOME environment had something similar, but it probably has been removed with version 3 of GNOME.
You can 'mount' the guests file system into your MS-Windows file system. not sure about the details how this works in MS-Windows, but I am sure that at least newer versions of MS-Windows have gained such feature. Most likely you are still limited to creating something like a "network harddrive" or something, in other systems (linux, unix, macOS) you can mount whereever in the file system you like. You can use any protocol for this, as long as it is supported by the mounting tools of your local system.
Again two options:
2.a You mount the whole virtual disk. Easy, but might be a problem if that disk is currently used by the guest system.
2.b You export the virtual disk by starting some server in the virtual system: samba is most likely your choice. Then you can mount that smb file export inside your MS-Windows system and start hacking.
Have fun!

Related

Can I run one WSL2 virtual machine instance on two system?

I'm new to the WSL2 and wondering if it's possible to run the same WSL2 ubuntu instance on both my desktop and laptop.
Now I am able to use wsl --export and wsl --import method to save and load the system to/from my portable hard drive. But these methods takes a long time.
I notice that wsl --import load a file named ext4.vhdx. Is there a way to load straightly from this file?
Update v2.0:
I was able to get a workaround and it works great.
Thanks to Booting from vhdx here, I was able to load straightly from my vhdx file on my portable hard disk. Windows track down its subsystem with regedit, So we can write our own(p.s: make sure to get BasePath right, it starts with "\\\\?", or you will not be able to access the subsystem' filesystem on your host system.):
Windows Registry Editor Version 5.00
[HKEY_USERS\【your SID here】\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{【UUID here】}]
"State"=dword:00000001
"DistributionName"="distribution name"
"Version"=dword:00000002
"BasePath"="vhdx folder path" 【 e.g. "\\\\?\\E:\\S061\\WSL\\ubuntu-20"】
"Flags"=dword:0000000f
"DefaultUid"=dword:000003e8
I suppose the best way to do this would be to store ext4.vhd on a network storage device accessible to both devices.
I have previosly mentioned how to move ext4.vhd. You can check that out here
Basically you need to export from one machine and import it while making sure the vhd file is configured for wsl to access from the network storage
Since this should *officially* not supported expect some performance hits
Another way would be to run WSL on one computer and ssh/remote desktop to it from another device on the network
I'm of the strong belief that sharing the same ext4 vhd between two VM's simultaneously would be a bad idea. See this and this Unix & Linux StackExchange, including the part about ...
note that sharing LVs/partitions on a single disk between the servers at the same time is NOT very safe. You should only access whole disks from any of the servers at one time.
However, as dopewind's answer mentioned, you can access the WSL instance on one computer (probably the desktop) from another (e.g. the laptop). There are several techniques you can use:
If you have Windows 10 Professional or Enterprise on one of the computers, you can enable Remote Desktop, which allows you to access pretty much everything on one computer from another. RDP ("Remote Desktop Protocol") even works from other devices such as an iPad or Android tablet (or even a phone, although that's a bit of a small screen for a "desktop"). That said, there are better, more idiomatic solutions for WSL ...
You could enable SSH server on the Windows 10 computer with the WSL instance (instructions). This may sound counterintuitive to some people, since Linux itself running in the WSL instance also includes an SSH server (by default). But by SSH'ing from (for example) your laptop into your desktop's Windows 10, you can then launch any WSL instance you have installed (if you choose to install more than one) via wsl -d <distroName>. You also avoid a lot of the network unpleasantness in the next option ...
You could, as mentioned above, enable SSH on the WSL instance (usually something like sudo service ssh start) and then ssh directly into it. However, note that WSL2 instances are NAT'd, so there's a whole lot more hackery that you have to do to get access to the network interface. There's a whole huge thread on the WSL Github about it. Personally, I'd recommend the "Windows SSH Server" option mentioned about to start out with, then you can worry about direct SSH access later if you need it.
Side note: Even though I have SSH enabled on my WSL instances, I still use Windows SSH to proxy to them, to avoid these networking issues.

How to Install a Vagrant Box on a Bare Metal Machine?

Is there an established way to take a Vagrant box and use it as the operating system for a "bare metal" machine, i.e. a normal computer and not a hypervisor, without having to sit through an installation process?
Now I understand the common response will probably be "install an OS regularly and then use a proper configuration management tool like Puppet or Chef" but hear me out. Our IT organization would like to create a base Vagrant box with all security-related protocols and applications enforced. Then a configuration management tool like Puppet could install "useful" applications like databases and web servers on top of it.
This works best when a software developer wants to deploy a new utility to development environments or servers - they can write the Puppet code to install exactly what they want, which can be turned over to IT to run it on top of the validated Vagrant box to create a virtual machine server.
By hosting the Vagrant box internally, we can hide the security details from the developer while they write new Puppet code, they can test their Puppet code on the same environment they will run it on, and it will provision much faster during testing since the box is just downloaded once. Most "production" deployments will stay as Virtual Machines.
In rare circumstances, we may want a real, bare-metal server, not a VM, probably when we get new hardware to run more VMs or if the utility we need is very computationally intensive. It would be nice if the existing Vagrant box could be repurposed so bare-metal and virtual servers were indistinguishable.
EDIT: I found a post on askubuntu (https://askubuntu.com/questions/32499/migrate-from-a-virtual-machine-vm-to-a-physical-system) which seems to do what I want, can anyone verify if such a procedure would work on a Vagrant disk image, if there would be necessary cleanup (like Vagrant ssh keys) or if it could be generalized to non-Ubuntu operating systems (since it uses Live CD)?
A Vagrant box packaged for VirtualBox is essentially a virtual disk with metadata. Most likely it's going to have the VirtualBox tools and drivers installed, which won't do much good on a physical system. Not only that, the drivers for the physical system would need to be installed on the box image.
What you're talking about doing is a good use case for some sort of "ghosting" software that simply copies blocks of data to a physical disk. There's really no advantage to using Vagrant here that I can see.

how I can connect remotely to a machine and use the console, without knowing its IP address?

I need to remotely access to the linux console of some machine, but i dont have that IP (and looks like it will be a dinamyc ip)
I have my PC "A", and other PC "B". I have local access to both to install and configure whatever is required, but the PC "B" will be located elsewhere.
Is ssh the best way to go? how?
Thanks!
Since Yogipriyo offered a visual solution, here is how you can access SSH without the need of a GUI. Really, it depends on what you are comfortable with; I would personally recommend it.
There are plenty of ways to utilize SSH depending on your OS (that is, "computer A's OS"):
Windows: MobaXTerm, Cygwin, and Putty are the popular ones that I've heard about. I like MobaXTerm simply because you can have multiple tabs.
Mac: Most have the ability to SSH built in via the X11 terminal. You might need to install XQuartz to enable X11 port forwarding though if this isn't working for you.
*Nix: Just get to command line; you probably know that.
Once you are there, Vim is a great editor to know. This again is a "text-based" editor and thus lends itself well to use over SSH.
Keep in mind a lot of this is personal opinion, so explore and find what makes you most productive.
For visual solution, you can use Team Viewer.
It uses it's machine ID (which assigned by the team viewer application once you install it) to connect to the machine. I used it for 2 years at my previous job as remote support and it didn't have any trouble with dynamic IP as long as you have the target's team viewer ID.
For text based, as far as I know you need the target's IP or domain, but alas it still needs static IP.

dokan sshfs for windows

I read an article here about dokan sshfs for windows. I want to ask if you know similar software (free or not) in order to access windows partitions from windows. Samba is a always an answer, however I am seeking for something more secure.
You can use the Dokan SSHFS client with the OpenSSH server for Windows, you can configure OpenSSH like you would on UNIX, then use the Dokan SSH client to connect remotely, just as you would do on UNIX with sshfs.
When you say Samba, so you mean SMB? Samba is the *NIX client/server for SMB.
SSHFS for accessing Windows partitions from Windows ? Did you by any chance mean Linux partitions from windows ?
If windows-windows, then sorry, no. sshfs is a Linux/Unix feature, and microsoft does all it can to NOT make it work on Windows (after all, that would allow to easily and securely migrate from Windows to Linux). On Windows, you use WebDAV to accomplish similar things, needless to say WebDAV is way more insecure than sshfs.
If you meant accessing remote Linux partitions from Windows, then I had the same problem before:
Dokan doesn't work, at least not on Vista x64. (epic bluescreen crash)
The java sshfs explorer on sourceforge doesn't work, either.
Microsoft's services for unix (including sshfs) are only available on Vista 'Ultimate', not on < Ultimate, like my Vista business for example.
There are some commercial solutions, but first, they are way overpriced, and second, I wouldn't trust them, since they don't offer evaluation.
My solution was to install VirtualBox on Windows, and install an Ubuntu guest on it, mounting the host's C drive. You need to set the VirtualBox network adapter to bridged mode to make sshfs work with virtualization. I'm sorry, but so far that's the only free solution that really works...
imdisk driver, see if http://www.ltr-data.se/opencode.html helps.
From the documentation
It is even possible to boot a machine
with NTFS partitions using a Unix
Live-CD and use the included devio
tool to let ImDisk on another computer
running Windows on the network mount
the NTFS partition on the machine you
booted with the Unix Live-CD. This way
you can recover information and even
run chkdsk on drives on machines where
Windows does not boot.
I've been using Win SSHFS for awhile, is this what you're looking for?
https://github.com/Foreveryone-cz/win-sshfs/
It runs on top of Dokany

MAMP/LAMP native or virtual (Virtualbox/VMware)?

What is your preferred development environment ?
Native
WAMP/MAMP/LAMP (Apache, MySQL, PHP) on Windows/MacOS/Linux
Working copy local, SVN/CVS on server
IDE/Editor on the same system (Eclipse, Aptana, Zend...)
Virtual/Native (Server on VM)
LAMP on VirtualBox/VMware
working copy in the VM
IDE/Editor on host, access to the VM with Samba, FTP, SFTP (eventually mapping with tools like WebDrive)
Virtual (VM)
Complete development environment running in a VM (server, tools, IDE)
Host is only used for special tools not available on the OS running in the VM
All have pros and cons.
With BitNami stacks you can run the exact same XAMP environment locally or remotely (and make sure everybody on your team is running the exact same stack). It is free and works on Windows, Linux, Mac.
I like having the SVN repository somewhere on a web server.
It's reasonably secure (using Apache WebDAV), and it gives me a good chance of recovering quickly from any disasters that may befall my main development machine. I have the luxury of control over my own web server, but there are lots of cheap hosts that will do the job at low cost.
As regards VM or no VM:
Advantages of VM - very fast recovery from screwing up your development environment
Ability to try out different versions or upgrades quickly
If you have many systems running the VM host, ability to quickly move the whole environment
Can choose any Host
Disadvantages of VM - performance impact; extra setup complexity.
On balance, I go for "no VM" if all the tools are available on my host system, but I do use VM when I need to run a different OS (the host system is a Mac Pro, so if I need Visual Studio, I do it with Parallels).