{"id":1226,"date":"2023-03-28T09:41:22","date_gmt":"2023-03-28T12:41:22","guid":{"rendered":"https:\/\/blog.galsoft.duckdns.org\/?p=1226"},"modified":"2023-03-28T09:42:05","modified_gmt":"2023-03-28T12:42:05","slug":"tips-ssh","status":"publish","type":"post","link":"https:\/\/blog.galsoft.com.ar\/?p=1226","title":{"rendered":"Tips SSH"},"content":{"rendered":"<h5 class=\"wp-block-heading\">Para interactuar con el servidor remoto agregamos <strong>-t<\/strong>, as\u00ed:<\/h5>\n<pre class=\"wp-block-preformatted\">ssh -t rpi htop<\/pre>\n<h5 class=\"wp-block-heading\">Ejecutar un script local en servidor remoto<\/h5>\n<pre class=\"wp-block-preformatted\">ssh rpi 'bash -s' &lt; mi-script-local.sh<\/pre>\n<h5 class=\"wp-block-heading\">Ejecutar script como otro usuario<\/h5>\n<pre class=\"wp-block-preformatted\">ssh rpi \"sudo su pollo -c 'mkdir directorio' \"<\/pre>\n<h5 class=\"wp-block-heading\">Ejecutar el mismo script en muchos servidores<\/h5>\n<pre class=\"wp-block-preformatted\">for i in $(cat lista-servidores.txt)<br>do<br>\u2022   ssh usuario@$i \"sudo su usuario-con-privilegios -c 'apt update &amp;&amp; apt upgrade -y' \"<br>done<\/pre>\n<h6 class=\"wp-block-heading\">Automatizar tarea anterior<\/h6>\n<p>Creamos lista-servidores.txt con el siguiente contenido:<\/p>\n<pre class=\"wp-block-preformatted\">192.168.1.5<br>rpi<br>192.168.1.20<\/pre>\n<p>Creamos script.sh con el siguiente contenido:<\/p>\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br>uptime<\/pre>\n<p>Creamos remote-exec.sh con el siguiente contenido:<\/p>\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br>\u200b<br>servidores=$(cat lista-servidores.txt)<br>\u200b<br>for host in $servidores; do<br> \u00a0 ssh $host 'bash -s' &lt; script.sh<br>done<\/pre>\n<p>Damos permisos de ejecuci\u00f3n a ambos scripts:<\/p>\n<p><code>chmod +x script.sh remote-exec.sh<\/code><\/p>\n<p>Ejecutamos el script:<\/p>\n<p><code>bash remote-exec.sh<\/code><\/p>","protected":false},"excerpt":{"rendered":"<p>Para interactuar con el servidor remoto agregamos -t, as\u00ed: ssh -t rpi htop Ejecutar un script local en servidor remoto ssh rpi &#8216;bash -s&#8217; &lt; mi-script-local.sh Ejecutar script como otro usuario ssh rpi &quot;sudo su pollo -c &#039;mkdir directorio&#039; &quot; Ejecutar el mismo script en muchos servidores for i in $(cat lista-servidores.txt)do\u2022 ssh usuario@$i &quot;sudo [&hellip;]<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1226","post","type-post","status-publish","format-standard","hentry","category-linux","entry"],"_links":{"self":[{"href":"https:\/\/blog.galsoft.com.ar\/index.php?rest_route=\/wp\/v2\/posts\/1226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.galsoft.com.ar\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.galsoft.com.ar\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.galsoft.com.ar\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.galsoft.com.ar\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1226"}],"version-history":[{"count":2,"href":"https:\/\/blog.galsoft.com.ar\/index.php?rest_route=\/wp\/v2\/posts\/1226\/revisions"}],"predecessor-version":[{"id":1228,"href":"https:\/\/blog.galsoft.com.ar\/index.php?rest_route=\/wp\/v2\/posts\/1226\/revisions\/1228"}],"wp:attachment":[{"href":"https:\/\/blog.galsoft.com.ar\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.galsoft.com.ar\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.galsoft.com.ar\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}