SSH Onto a Remote Server to Run Commands

Refer: http://malcontentcomics.com/systemsboy/2006/07/send-remote-commands-via-ssh.html

The basic form looks something like this:

ssh systemsboy@rhost.systemsboy.edu 'ls -l'

where "systemsboy" is actually your username on the remote host, and "rhost.systemsboy.edu" is your remote system. The command you're sending is contained in single quotes.

Here is an example sending multiple commands:

ssh systemsboy@rhost.systemsboy.edu 'ls -l; ps -aux; whoami'

wherein each command is separated by a semicolon.

Finally, here is an example sending a command that requires user interaction:

ssh -t systemsboy@rhost.systemsboy.edu 'top'

Note the -t flag. That tells ssh that you'll be interacting with remote shell. Without the -t flag top will return results after which sshwill log you out of the remote host immediately. With the -t flag, ssh keeps you logged in until you exit the interactive command. The -t flag can be used with most interactive commands, including text editors like pico and vi.

Sending remote commands via ssh is incredibly handy when writing shell scripts as it allows you to run your scripts locally even if those scripts are meant to effect changes on a remote machine. I just wrote a script, for instance, that sets up vacation mail forwarding for staff members. Without these remote commands I would have had to have staff members log directly onto the mail server and run the scripts from the command line, which I don't think they'd be too happy about. With ssh remote commands, I can give them the scripts and they can run them right from their Desktops. Believe me, they much prefer this.

Quick SSH on Ubuntu 12.04

sudo apt-get install openssh-server

After the installation, you can SSH onto your machine, this is not secure and good for a home network solution, but you'll need to investigate security if you are going to hang the machine outside a Firewall.

Ubuntu SSH Steps

1. Ubuntu needs to run in Virtual Box as a bridged network

2. Make sure you have SSH installed, it will automatically start
sudo apt-get install ssh

3. Use ifconfig to get the virtual machine's IP address

4. Use putty and SSH onto that machine or FileZilla

You can remove SSH by (did not disable)
sudo apt-get remove ssh

Start/Stop with:
sudo /etc/init.d/ssh stop
sudo /etc/init.d/ssh start

SSH For SCP Fix

From: Turner, Andrew (HAL)
Sent: Tuesday, January 03, 2012 11:36 AM
To: Lee, Scott (HAL); Hoggard, Chad (HAL); Hofsetz, Therron (HAL); Siwek, John (HAL)
Cc: Mounagurusamy, Jayakumar (HAL); Harris, Tyrone (HAL); Augustine, Anila (HAL); Ruckman, Maurice (HAL)
Subject: RE: FAILURE FAILURE FAILURE Environment - prod : Error -- CC Applied Onboard Failed SCP For File WEBC20111229CC.txt

Here are my notes to fix the issue:

Open Dos Window

ntrights +r SeAssignPrimaryTokenPrivilege -u cyg_server ntrights +r SeCreateTokenPrivilege -u cyg_server

--restart CYGWIN sshd service using the following net stop sshd net start sshd

From: Turner, Andrew (HAL)
Sent: Thursday, February 02, 2012 10:06 AM
To: Siwek, John (HAL); Hoggard, Chad (HAL); Lee, Scott (HAL); Ruckman, Maurice (HAL); Harris, Tyrone (HAL)
Cc: Mounagurusamy, Jayakumar (HAL); Augustine, Anila (HAL); Hofsetz, Therron (HAL)
Subject: RE: FAILURE FAILURE FAILURE Environment - prod : Error -- CC Applied Onboard Failed SCP For File EDBC20120124CC.txt

Hi John

The user name is cyg_server

This is a local user on the HALRES01 box that runs the SSHD service.

Getting Ubuntu SSH Server running, allows nomachine to work too

No SSH - No No Machine

I've been using No Machine to remote into machines for quite a while now and all I can say is that I'll never go back to VNC.

I recently completely reinstalled my fileserver with Ubuntu 8.10 and installed the no machine server in the recommended way. I fired up the client and got a "connection refused on port 22".

It had been so long since I did a fresh installation of Ubuntu that I'd forgotten that Ubuntu ships with a SSH client but not the server. I found some useful info here.

To get your system up to speed all you need to do is:
sudo apt-get install openssh-server openssh-client

You can test it with:
ssh your_user@localhost

Now your system can frolic in its No Machine goodness!