How to run a program in SSH? - ssh

So I want to run an .exe in SSH but can't figure out, help please?
I'm trying to run a server for my game i'm making and need this on my vps so anyone can connect, but can't figure out how to run it in SSH on my vps.

SSH is a protocol and will, by itself, never run any program. Depending on the Shell you're running inside SSH and the operating system in use you will start your executable:
Linux: ./program
Windows: program.exe
Note: exe usually indicates a Windows program. Most Linux/Unix servers have SSH access, while Microsoft servers usually don't. Are you trying to start a windows exe on a Linux machine? That will not work (ever). Unless it is a .NET executable, in which case you can start in using the mono-framework.

You need ./ before the program name, like this
./program.exe

You want to install an SSH server and make it run your own program instead of the default shell? How to configure that depends entirely on which product / package you are using; but perhaps rephrasing the problem for you is sufficient for helping you find the configuration directive you need in the documentation.

For windows, you can use the following command:
ssh username#remotePcIP "\file.exe"

Linux: This will run a series of commands remotely into a remote machine with ssh (make sure your username has direct access and password is not required):
ssh remotemachine ' command1 | command2 | command3 '

Related

Can Vagrant suffice my requirement?

I have been looking out for ways to setup an automation environment and I found this application named Vagrant. I read the docs on the site, however I wanted to know from the experts out there if Vagrant with Oracle VirtualBox would suffice my needs.
I need to have a script that will call Vagrant to initialize a VM [The VM-Image is always the same - Windows Server 2008 R2]
I need to copy some of my project related files from a shared location onto the VM
Call a Batch file that will take care of test runs for me inside the VM
Once my test run is complete, This VM needs to be self destroyed/destructed.
Also, I would like to know if the Image be a custom .ISO file?
Sounds like Vagrant and VirtualBox will work for that scenario. Also, you might find that running commands in the VM using WinRM or SSH may be the easiest way to launch tests.
If you haven't already seen it, the blog post about Windows support in Vagrant 1.6 is informative: https://www.vagrantup.com/blog/feature-preview-vagrant-1-6-windows.html
Creating a VirtualBox/Vagrant base VM from an .iso should work, and you can then do all of your work using the VM from that point onward.
To get started, you might try these steps:
Create a VirtualBox VM from your Windows .iso, using the VirtualBox GUI or cmdline tools.
Once you have the VM in the state you want it, shut it down and package it as a vagrant box - for example, on a Mac that step looks like (where Win7x64 is the dir containing the VirtualBox VM):
cd ~/VirtualBox\ VMs
vagrant package --base Win7x64 --output win7x64_base.box
Once that finishes, tell vagrant about the new base box:
vagrant box add win7x64_base /path/to/win7_base.box
Then you can vagrant init/vagrant up the VM:
mkdir win7 && cd win7
vagrant init win7x64
vagrant up
To enable SSH access, I installed Cygwin in the VM and configured sshd. So, after launching you can SSH in by running vagrant ssh
Note that if there's no Windows user in the VM named 'vagrant', you can specify the SSH username to use with vagrant ssh by placing this in your Vagrantfile:
config.ssh.username = 'user1'
As mentioned above, WinRM is also an option for remotely running commands.
And Vagrant apparently has some convenience features to make it easy to RDP into the VM, but I haven't looked at that.

Fedora how to automatically run the ssh daemon

I would like to know what are the ways to automatically start daemons (sshd) in Fedora system. I know I can write a startup script that will put on /etc/init.d/.
What are the other options?
Somewhere I read that now in the new version of this can be done using the commands in the terminal, but I do not remember what it was.
EDIT: My 2 question.
I install ssh from source. When keys are generated for a server? During the installation?
You can do this via systemctl:
systemctl enable sshd.service

Jenkins - Windows XP Slave

I'm having big problems connecting a windows slave to a working jenkins CI setup.
How do you connect using command on the master? I've tried the following command:
bash -c 'ssh user#hostname cmd /c "java -jar C:/jenkins/slave.jar -text 2>C:/jenkins/slave_error.txt"'
This successfully connects, BUT all commands talk to whatever shell has been spawned by the ssh server. This should be a new cmd shell (is this akin to a new bash shell?) as if the local user ran cmd.exe. freeSSHd claims to do this, but I can't get it to work. Instead the sshd server shipped with cygwin spawns a cmd shell, which spawns an emulated bash shell, which spawns an emulated cmd shell, which calls "java -jar slave.jar".
It seems that through all those layers of emulation, a) some system environment variables are lost, and b) windows commands run slower. Does anyone else connect to windows with ssh, and if so, how? I haven't found any information on running windows builds remotely with purely command line calls.
The build works perfectly on windows 7 through Java Web Start.
Why does the Java Web Start option, which creates a service on the slave, disconnect after ~20 hours? This option works great, but we cannot tolerate this sort of unreliability. Windows 7 has no such issue.
Why is connection through DCOM seemingly impossible to set up?
In case anyone else is trying to use "Launch slave agents on Unix machines via SSH", it cannot work at all for a windows slave. Use "Launch slave via execution of command on the Master".
Any advice is appreciated.

Apache Web Development on Cygwin

I'm trying to get an Apache server running on my Cygwin setup to follow the Java Ranch Cattle Drive tutorials online (basically, to learn Java EE web page development that uses a MySQL back end.)
I used the Cygwin Setup program to install httpd (which is how I installed most other dev tools I use on cygwin) and it says install complete, yet when I run 'httpd' it cannot find the command. It also appears the expected install directory (/usr/local/apache...) doesn't exist.
Does anyone have any experience using this setup, and if so, you could walk me through the initial steps of getting the server up and running and getting a browser to display the server's default page?
To keep answers focused, I didn't want to discus the drawbacks of running Apache on a Windows system - this is just for learning purposes. Thanks in advance.
Looking at the Cygwin Package Listing for httpd, you can see that the executable is installed under /usr/sbin.
So, if /usr/sbin is not on your PATH (it isn't on mine, not by default anyhow), you would actually run:
/usr/sbin/httpd
And btw, if you would like to list the files installed for a certain package, you can use cygcheck:
cygcheck -l httpd
cygrunsrv -I Apache -p /usr/sbin/httpd -a "-X"
This will solve the problem. This assumes you already have cyrunsrv set up. The reason httpd fails with cygrunsrv if you leave out the -X is that the process disconnects from the terminal and cygrunsrv considers that a failure. The -X option for httpd is the debug or terminal mode.
I couldn't find any detailed information on how to get Apache working on Cygwin, so here it is if someone's interested:
Install the httpd-* and httpd-mod_* packages you need. Note that the packages named "Apache" are deprecated. You need the ones named "httpd" (which are actually Apache).
Install cygrunsrv (normally this is a default Cygwin package)
Run /usr/bin/cygserver-config as admin. This is needed because Apache requires an IPC server running.
Open services.msc, then go to the CYGWIN Cygserver. Right-click on it and start it. If you don't do this, you'll probably get errors like "AH00023: Couldn't create the proxy mutex".
Finally, start Apache by running /usr/sbin/apachectl restart
Config is in /etc/httpd/.
Some information about running Apache on Cygwin:
http://httpd.apache.org/docs/1.3/cygwin.html
http://www.issociate.de/board/goto/895433/apache2_does_not_start_in_cygwin.html
http://www.cygwin.com/ml/cygwin-apps/2005-02/msg00085.html
Personally, I would recommend installing WAMPServer or other WAMP stack and do it that way. There is no difference, except that you'll need to control Apache through Windows commands [net start, net stop], not Cygwin's ones.

IntelliJ - Running Program as Sudo

Developing a program on OSX using Java and IntelliJ. Deals with network sockets and ICMP. Hence, the program needs to be run as root or sudo'd on OSX. Program runs fine from a terminal window outside IntelliJ under sudo. However, I would like to debug and run it from IntelliJ (V9). In IntelliJ it errors (I need root privs to enumerate network devices). I know how to pass program and VM parameters in IntelliJ but now how to hit Run and/Debug and have it run under sudo? What is needed is basically sudo java ...... MyProgram instead of java ..... MyProgram Any ideas or workarounds.
I came out with an answer and wanted to share it just in case anyone else runs into this. To solve the problem, I took my cue from what I do with QT & QT Creator when doing network programming.
On OSX, I opened up a terminal window and cd'd down to/Applications/IntelliJ IDEA 9.0.3.app/Contents/MacOS. There you will find a file called idea which launches the IDE. I ran that as sudo (sudo ./idea). That took care of permissions on anything Intellij launched and I could debug and step through my code as needed.
sudo /Applications/IntelliJ IDEA 9.0.3.app/Contents/MacOS/idea
Since this is a dev machine and I am in control of it security is not an issue in this case.
Hope it helps someone else out.
Inside a terminal:
sudo -s
give access to the root user.
from there you could run the Idea IDE using the script:
/Applications/IntelliJ\ IDEA*/bin/idea.sh
and in this way I'm able to work on network where permission errors where printed before.
Debugging of sudo programs is disallowed by the operating system unless the debugger is running as root, for security reasons.
So, even if you can figure out how to get IntelliJ to use sudo it won't do you any good.
I know this is not what OP directly asked -
In case someone needs to do this on Linux (Ubuntu), e.g. in order to update Idea, just run from command line:
sudo /usr/local/bin/idea
Only make sure once the Update and Restart is finished to actually close Idea and start it normally
I agree with #Darron, it is not recommended to execute IntelliJ with sudo.
You can execute with IntelliJ terminal instead.
I maintain my project in IntelliJ. When I need to execute a unit test that requires sudo access, I just open IntelliJ terminal and type:
sudo gradle test
Good luck!