ssh-manual.adoc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. [#action-ssh]
  2. = SSH (manual setup)
  3. include::partial$action_examples/ssh_intro.adoc[]
  4. NOTE: There is an easy method of setting up SSH with OliveTin, which is described in the <<action-ssh-easy,SSH (easy setup)>> section. This section is for those who want to set up SSH manually.
  5. :systemd: Easy
  6. :container: Needs some setting up - see the <<ssh-container,SSH Container setup instructions>>
  7. include::partial$action_examples/actionHeader.adoc[]
  8. .OliveTin `config.yaml`
  9. [source,yaml]
  10. ....
  11. actions:
  12. # This will SSH into a server an run the command 'service httpd restart'
  13. - title: Restart httpd on Server 1
  14. shell: ssh root@server-with-olivetin 'service httpd restart'
  15. icon: ping
  16. timeout: 5
  17. ....
  18. *Note about SSH keys*: You should make sure that the user that OliveTin is running as has access to a SSH key. This applies to container images as well. The setup instructions below briefly explain how to generate a SSH key and make it accessible to OliveTin which is running inside a container.
  19. [#ssh-container]
  20. SSH from inside a Container - setup instructions
  21. This is a two step process;
  22. * [red]#<<ssh-step-1,Step 1>># Give OliveTin a SSH key
  23. * [red]#<<ssh-step-2,Step 2>># Setup actions that use SSH with this key
  24. Visually, this is what it looks like - OliveTin is running in the (orange) container, and then can either connect back to _server-with-olivetin_ or _server2_.
  25. image::../ssh-diagram.png[]
  26. The steps in detail are below;
  27. [#ssh-step-1]
  28. [red]#Step 1#: Give OliveTin a SSH key
  29. Open a terminal window on _server-with-olivetin_.
  30. [loweralpha]
  31. . Create the `/opt/OliveTinSshKeys` directory, to create a shared directory for your SSH key file.
  32. +
  33. [source,bash]
  34. ----
  35. root@server-with-olivetin: mkdir /opt/OliveTinSshKeys
  36. ----
  37. +
  38. This will later be used as a "volume mount" when you create a docker container.
  39. . Run `ssh-keygen` to generate a SSH key just for OliveTin.
  40. +
  41. [source,bash]
  42. ----
  43. root@server-with-olivetin: ssh-keygen
  44. ----
  45. [lowerroman]
  46. .. Enter the file in which to save the key: `/opt/OliveTinSshKeys/id_rsa`
  47. .. Enter passphrase (empty for no passphrase): `<enter>`
  48. +
  49. This will create a passwordless SSH key that OliveTin can use. It is safe as long as nobody steals your SSH key file! OliveTin cannot enter passwords into SSH keys, so you have to leave the password blank.
  50. . You should get something that looks like this. If you get a "permission denied" error when creating files, try running `chmod 0777 /opt/OliveTinSshKeys` and try again.
  51. +
  52. [source]
  53. ----
  54. root@server-with-olivetin: ssh-keygen
  55. Generating public/private rsa key pair.
  56. Enter file in which to save the key (/root/.ssh/id_rsa): /opt/OliveTinSshKeys/id_rsa
  57. Enter passphrase (empty for no passphrase):
  58. Enter same passphrase again:
  59. Your identification has been saved in /opt/OliveTinSshKeys/id_rsa
  60. Your public key has been saved in /opt/OliveTinSshKeys/id_rsa.pub
  61. The key fingerprint is:
  62. SHA256:t+vGUn+MTeOtRDpxKanO3Cg63+gvAHslZCe3YVNnfWU root@server-with-olivetin
  63. The key's randomart image is:
  64. +---[RSA 3072]----+
  65. | .. o. E|
  66. | + * o ...|
  67. | o = + . |
  68. | . . o . . |
  69. | o oS . + + |
  70. | . o ..o *o |
  71. | . . oo.o*.o |
  72. | . +*o+oo= .|
  73. | .=+BX .... |
  74. +----[SHA256------+
  75. ----
  76. +
  77. This will create two files, `/opt/OliveTinSshKeys/id_rsa` (your private key) and `/opt/OliveTinSshKeys/id_rsa.pub` (your public key).
  78. . Copy your public key to every server you want to connect to.
  79. +
  80. Using the `ssh-copy-id` command is a really quick and safe way to do this.
  81. +
  82. ----
  83. root@server-with-olivetin: ssh-copy-id -i /opt/OliveTinSshKeys/id_rsa.pub root@localhost
  84. (enter your SSH password)
  85. root@server2: ssh-copy-id ssh-copy-id -i /opt/OliveTinSshKeys/id_rsa.pub root@server2
  86. (enter your SSH password)
  87. ----
  88. +
  89. You will be asked to login with a password for each server.
  90. +
  91. After you have done that, you will then be able to login with the ssh key instead. Here is a quick way that you can test your SSH key manually;
  92. +
  93. ----
  94. root@server-with-olivetin: ssh -i /opt/OliveTinSshKeys/id_rsa root@server2
  95. (you should login without a password)
  96. ----
  97. . Give the SSH key to the OliveTin container.
  98. +
  99. The way to do this is via a "volume mount". When you create the container, you use "-v" to specify a volume.
  100. +
  101. You should mount your SSH keys directory into the OliveTin user's home directory by creating the container like this;
  102. +
  103. .If you want to create the container from the command line
  104. ----
  105. docker run -v /opt/OliveTinSshKeys/:/home/olivetin/.ssh/ -v /etc/OliveTin/:/config --name OliveTin jamesread/olivetin
  106. ----
  107. +
  108. .If you are using docker-compose
  109. [source,yaml]
  110. ----
  111. services:
  112. olivetin:
  113. container_name: olivetin
  114. image: jamesread/olivetin
  115. volumes:
  116. - "/etc/OliveTin/:/config"
  117. - "/opt/OliveTinSshKeys:/home/olivetin/.ssh"
  118. ports:
  119. - "1337:1337"
  120. restart: unless-stopped
  121. ----
  122. This also works for things like SSH configuration files, if you want to use them. This is step 1 complete from the diagram above.
  123. [#ssh-step-2]
  124. [red]#Step 2#: Setup actions that use SSH with this key
  125. Thankfully, step 2 is very simple! `ssh` commands in your OliveTin `config.yaml` should work without a password!, and allow OliveTin to access services, files, and other stuff outside of the OliveTin container.
  126. .OliveTin `config.yaml`
  127. [source,shell]
  128. ....
  129. actions:
  130. # This will SSH into a server an run the command 'service httpd restart'
  131. - title: Restart httpd on Server 1
  132. shell: ssh root@server-with-olivetin 'service httpd restart'
  133. icon: ping
  134. timeout: 5
  135. ....