Skip to main content
edited body
Source Link
Martin Braun
  • 823
  • 2
  • 14
  • 22

If you use a SSH config file on your systemto connect, you can embed a startup command that will only execute when you connect the machinehost.

For this insert / edit the following into your ~/.ssh/config on your client machine:

Host myhost
  HostName *.*.*.*
  User root
  RequestTTY force
  RemoteCommand cd / && bash -i

Put the appropriate hostname and append a new line Port XX if the port differs from 22. The sample will cd in the root of the server. && bash -i and RequestTTY force are essential to continue usage of the remote terminal.

To connect to your host you have to install your public key on the target machine that you can retrieve like so:

cat ~/.ssh/id_rsa.pub

And install on the remote like so:

mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys && chmod 644 ~/.ssh/authorized_keys && echo "YOUR_PUBLIC_KEY" >> ~/.ssh/authorized_keys

Then you can simply connect the machine like so:

ssh myhost

And it will connect and execute the RemoteCommand.

If you use a config file on your system, you can embed a startup command that will only execute when you connect the machine.

For this insert / edit the following into your ~/.ssh/config on your client machine:

Host myhost
  HostName *.*.*.*
  User root
  RequestTTY force
  RemoteCommand cd / && bash -i

Put the appropriate hostname and append a new line Port XX if the port differs from 22. The sample will cd in the root of the server. && bash -i and RequestTTY force are essential to continue usage of the remote terminal.

To connect to your host you have to install your public key on the target machine that you can retrieve like so:

~/.ssh/id_rsa.pub

And install on the remote like so:

mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys && chmod 644 ~/.ssh/authorized_keys && echo "YOUR_PUBLIC_KEY" >> ~/.ssh/authorized_keys

Then you can simply connect the machine like so:

ssh myhost

And it will connect and execute the RemoteCommand.

If you use a SSH config file to connect, you can embed a startup command that will only execute when you connect the host.

For this insert / edit the following into your ~/.ssh/config on your client machine:

Host myhost
  HostName *.*.*.*
  User root
  RequestTTY force
  RemoteCommand cd / && bash -i

Put the appropriate hostname and append a new line Port XX if the port differs from 22. The sample will cd in the root of the server. && bash -i and RequestTTY force are essential to continue usage of the remote terminal.

To connect to your host you have to install your public key on the target machine that you can retrieve like so:

cat ~/.ssh/id_rsa.pub

And install on the remote like so:

mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys && chmod 644 ~/.ssh/authorized_keys && echo "YOUR_PUBLIC_KEY" >> ~/.ssh/authorized_keys

Then you can simply connect the machine like so:

ssh myhost

And it will connect and execute the RemoteCommand.

added 13 characters in body
Source Link
Martin Braun
  • 823
  • 2
  • 14
  • 22

If you use a config file on your system, you can embed a startup command that will only execute when you connect the machine.

For this, first run

nano ~/.ssh/config

to open the config file. Then you can insert / edit it to contain something like thisthe following into your ~/.ssh/config on your client machine:

Host myhost
  HostName *.*.*.*
  User root
  RequestTTY force
  RemoteCommand cd / && bash -i

ThisPut the appropriate hostname and append a new line Port XX if the port differs from 22. The sample will cd in the root of the server. && bash -i and RequestTTY force are essential to continue usage of the remote terminal.

Don't forgetTo connect to input the right IP in HostName, thenyour host you have to install your public key on the target machine that you can retrieve like so:

~/.ssh/id_rsa.pub

And install on the remote like so:

mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys && chmod 644 ~/.ssh/authorized_keys && echo "YOUR_PUBLIC_KEY" >> ~/.ssh/authorized_keys

Then you can simply connect the machine like so:

ssh myhost

And it will connect and execute the RemoteCommand.

If you use a config file on your system, you can embed a startup command that will only execute when you connect the machine.

For this, first run

nano ~/.ssh/config

to open the config file. Then you can insert / edit it to contain something like this:

Host myhost
  HostName *.*.*.*
  User root
  RequestTTY force
  RemoteCommand cd / && bash -i

This sample will cd in the root of the server. && bash -i and RequestTTY force are essential to continue usage of the remote terminal.

Don't forget to input the right IP in HostName, then install your public key on the target machine that you can retrieve like so:

~/.ssh/id_rsa.pub

And install on the remote like so:

mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys && chmod 644 ~/.ssh/authorized_keys && echo "YOUR_PUBLIC_KEY" >> ~/.ssh/authorized_keys

Then you can simply connect the machine like so:

ssh myhost

And it will connect and execute the RemoteCommand.

If you use a config file on your system, you can embed a startup command that will only execute when you connect the machine.

For this insert / edit the following into your ~/.ssh/config on your client machine:

Host myhost
  HostName *.*.*.*
  User root
  RequestTTY force
  RemoteCommand cd / && bash -i

Put the appropriate hostname and append a new line Port XX if the port differs from 22. The sample will cd in the root of the server. && bash -i and RequestTTY force are essential to continue usage of the remote terminal.

To connect to your host you have to install your public key on the target machine that you can retrieve like so:

~/.ssh/id_rsa.pub

And install on the remote like so:

mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys && chmod 644 ~/.ssh/authorized_keys && echo "YOUR_PUBLIC_KEY" >> ~/.ssh/authorized_keys

Then you can simply connect the machine like so:

ssh myhost

And it will connect and execute the RemoteCommand.

Source Link
Martin Braun
  • 823
  • 2
  • 14
  • 22

If you use a config file on your system, you can embed a startup command that will only execute when you connect the machine.

For this, first run

nano ~/.ssh/config

to open the config file. Then you can insert / edit it to contain something like this:

Host myhost
  HostName *.*.*.*
  User root
  RequestTTY force
  RemoteCommand cd / && bash -i

This sample will cd in the root of the server. && bash -i and RequestTTY force are essential to continue usage of the remote terminal.

Don't forget to input the right IP in HostName, then install your public key on the target machine that you can retrieve like so:

~/.ssh/id_rsa.pub

And install on the remote like so:

mkdir -p ~/.ssh && chmod 700 ~/.ssh && touch ~/.ssh/authorized_keys && chmod 644 ~/.ssh/authorized_keys && echo "YOUR_PUBLIC_KEY" >> ~/.ssh/authorized_keys

Then you can simply connect the machine like so:

ssh myhost

And it will connect and execute the RemoteCommand.