Automate Remote SSH Control of Computers with Expect Scripts [Tutorial]

Поділитися
Вставка
  • Опубліковано 14 січ 2025

КОМЕНТАРІ • 93

  • @rene_from_so_cal
    @rene_from_so_cal 3 роки тому +4

    This brings back memories. I used this exact method of ssh-ing and executing tasks on a system while supporting remote staff in Ukraine while me located out in LAX some years ago. Love the combo of Linux w/Expect scripting. Excellent creativity!
    Good work!

    • @slambrew3849
      @slambrew3849 3 роки тому +1

      Damn, is the CIA still hiring?
      (I kid I kid)

  • @apurvsharma78
    @apurvsharma78 3 роки тому +1

    OH MY GOD THIS CHANNEL HAS SO MUCH CONTENT! DUDE I WISH YT RECOMMENDED U EARLIER

  • @PixieSea
    @PixieSea 8 місяців тому +1

    00:34 The man that doesn't blink, winks.

  • @surajsharma4409
    @surajsharma4409 3 роки тому +1

    😍😍😍😍😍😍😍😍😘😘😘 NULL BYTE IS LOVE......

  • @lasourisRKO
    @lasourisRKO 2 роки тому +1

    I don't understand the interest :
    It looks like : you execute a script and you enter the password.
    So what the difference between that and root@server + password ?
    Always 2 things to write

  • @nikolas8741
    @nikolas8741 3 роки тому

    I love automation! great video❤️

  • @usbwarr1or
    @usbwarr1or 3 роки тому

    I love your videos on coding very helpful and helped me out alot

  • @kevinshumaker3753
    @kevinshumaker3753 3 роки тому

    Thanks for using motionEyeOS on one of your PIs.

  • @randomrat6421
    @randomrat6421 3 роки тому

    Excellent tutorial. Well explained. Thank you.

  • @Blentux
    @Blentux 3 роки тому +2

    Would it be possible to combine such ssh tasks via expect script with a python script? Just like bash commands can be executed within a python script, so could the same be done with expect? Or should ssh tasks be rather done with python only?

    • @thengakola6217
      @thengakola6217 3 роки тому +2

      pexpect, paramiko

    • @Blentux
      @Blentux 3 роки тому +1

      @@thengakola6217 thanks bro

  • @Dimrain13
    @Dimrain13 3 роки тому +1

    Expect is pretty bomb. I learned about it when I wanted to auto login to SFTP from another location to do periodic backups. Flawless.

  • @zipf
    @zipf 3 роки тому +1

    Yeeeees! The video I was looking for

  • @87321opc
    @87321opc 3 роки тому

    Awesome thanks for the info!! Great video and channel!!!

  • @undeze
    @undeze Рік тому

    Really cool. With great power comes…

  • @axolum8735
    @axolum8735 2 роки тому

    lol was looking for scripting in general, but this video solves an issue with my broken rpi

  • @zaczaemnowezycie7021
    @zaczaemnowezycie7021 3 роки тому

    Thank You Sir for video. 1:30 am here Kappa

  • @othernicksweretaken
    @othernicksweretaken 3 роки тому +2

    Isn't Expext written in Tcl, and doesn't it require its user to write their scripts in a tickle-ish style too?
    If my memory serves me correctly Tcl involved rife use of curly braces, or am I mixing this up with Lisp?
    As you can see I am not very much fond of either Tcl nor Lisp.
    I can remember that Tcl had a certain popularity in the 90s, especially among people who either needed to write Expect scripts or those who wanted to quickly script some sort of GUI for their otherwise dull CLI scripts, what would otherwise require much ado in C with an API to X Motif.
    But why would I need to write an Expect script to shutdown and power off my RasPi remotely?
    I use SSH key-based passwordless login to all my hosts anyway.
    This is the only requirement if you want to automate things e.g. with Ansible.
    Btw. you can even poweroff remote hosts through systemd's systemctl command.
    I think Expect made much more sense in the 90s when most people in the Unix realm still used telnet, and the BSD rlogin, remsh, and rsh commands to connect to their hosts and before Tatu Ylönen's (ha, I still remember the Finnish guy's name from the ssh manpage on HP-UX) SSH became available.
    Apropos, not to be taken seriously, doesn't a _grep | awk_ pipeline like in your little sample script qualify for the _Useless Use of Cat Award_ ?
    N.b. @08:25 if you want to avoid being forced to confirm the remote sshd's hostkey, when you login somewhere for the first time with ssh you could try to pass the following options to your ssh client.
    _ssh -o stricthostkeychecking=no -o userknownhostsfile=/dev/null ..._
    If you want to avoid always having to type these long option args (ok, we all use our shell's history anyway, don't we?) then just tuck those two options (they are case insensitive but for better readability use Camel case, you only have to type it once) into your ssh client's config file in _~/.ssh/config_ within a Host block definition on two separate lines, and substitute the equal sign between parameter and value by whitespace.
    For more fancy ssh client options consult man ssh_config.

    • @theeffectoflogic3
      @theeffectoflogic3 3 роки тому

      German, old & possibly fond of the letter 'k'

    • @othernicksweretaken
      @othernicksweretaken 3 роки тому

      @@theeffectoflogic3 which vocables did I spell incorrectly? English isn't my native tongue.
      And then, if I am aware of it, I do prefer the British spelling which may look to you Americans even older and more bizarre. In the context of IT I often even have to pull myself together not to write e.g. _programme_ .
      Thankfully most Unix commands only consist of two letter words.

    • @theeffectoflogic3
      @theeffectoflogic3 3 роки тому +1

      @@othernicksweretaken You depicted yourself as a veteran in the field, your profile picture shows the German flag with a banana, which is infamous as a source of potassium, which is represented by the letter 'K'... Can't believe you didn't understand such a logical reply.

    • @othernicksweretaken
      @othernicksweretaken 3 роки тому

      @@theeffectoflogic3
      Thank you for your explanatory reply.
      Of course you are right with your deductions. I have to admit that I didn't have the nutritional properties of bananas on my mind because I chose my avatar image with the halfway peeled off banana over the colours of my country's national flag for another reason, a very self-derisive one towards the current state of my nation.
      In German we have the expression _Bananenrepublik_ whose meaning I thought was very commonplace almost internationally, and I am sure that _banana republic_ has in English the same pejorative connotation, without even having to look it up.

  • @FarhanTauqeer
    @FarhanTauqeer 10 місяців тому

    why are we rebooting after the ssh connection in expect.exp script?

  • @edgecrush3r
    @edgecrush3r 3 роки тому

    How does this compare by lets say using Ansible for automation. You could make a playbook for localhost and do the above without issues, plus you will have the benefit of all controls and plugins if you want to extend.

  • @Thomas72B
    @Thomas72B 3 роки тому +1

    I only get the error message: ': not a valid identifier `loginpass and my_lookupdev: socket: Socket type not supported ! Where is the mistake ? ( Windows 10 Linux Subsystem Ubuntu 20.04 LTS )

    • @eagleeyeviewimages
      @eagleeyeviewimages 3 роки тому +2

      i get error line 15 i think it said, so dont feel too bad lol

    • @Thomas72B
      @Thomas72B 3 роки тому

      @@eagleeyeviewimages I still have error line 3! I'm just trying to figure out the mistake. Little success so far!

  • @tyranosurasmax
    @tyranosurasmax 3 роки тому

    I love this. Thank you

  • @eagleeyeviewimages
    @eagleeyeviewimages 3 роки тому +2

    I am getting a (file "expect. exp" line 15) help please

  • @Prasoonyoutubechannel
    @Prasoonyoutubechannel 2 роки тому

    I need help for calling a shell inside expect shell

  • @smidi4711
    @smidi4711 3 роки тому +5

    or using python with the library Pexpect and you can use sys or subprocess and paramiko for the ssh

    • @rene_from_so_cal
      @rene_from_so_cal 3 роки тому +1

      This sounds fun...you wouldn't have a tut on this would you? Maybe I'll piece this together...

    • @smidi4711
      @smidi4711 3 роки тому

      @@rene_from_so_cal actually I do

    • @justinappicelli7224
      @justinappicelli7224 3 роки тому

      @@rene_from_so_cal
      Awooda

    • @rinaso905
      @rinaso905 2 роки тому

      @@smidi4711 share it please ?

  • @runthomas
    @runthomas 2 роки тому

    i need to log onto a remote server via ssh and a key...
    then i need to run a command to update the certificates of the servers website
    then i need to restart a couple of services
    then i need to log off
    all this is to be run from a cron job
    is this possible....im a bit worried about using automatic ssh key logon..as i cannot send an ssh password over the line..and i need zero user input.

  • @s.aravindh6227
    @s.aravindh6227 3 роки тому

    Nice video bro 👍👍

  • @raducumihaicristian
    @raducumihaicristian 3 роки тому

    Thank you for this informations! Very useful.
    I have a task: I need to ssh into multiple switches (about 200. All the switches have very well defined names in the DNS) and I need to check one thing from their configuration. How about doing that? I guess I will need a way to grab the IP addresses, therefore modifying the 'arp-scan-l' line and then use a for loop I guess, right?
    In pseudocode it would be something like this.
    - grab all the ip addresses in the domain whose names starts with "blablabla"
    - foreach of these ip addresses spawn an ssh process ;
    - run the command for showing the switch configuration file.
    - eventually grab the config into a txt file or whatever.

    • @rinaso905
      @rinaso905 2 роки тому

      hi did you get any response or way to do it ?

  • @TamifluOne
    @TamifluOne 3 роки тому

    Brand new haircut dude...

  • @timlind3129
    @timlind3129 3 роки тому

    Example showing automation using SSH keys (so you don't have to login) and rexec command vs. expect? Expect is kinda wonky sometimes.

    • @zelja.
      @zelja. 3 роки тому

      Sometimes? I've been running the same script on 30 hosts for at least 15 years, and still have to fine tune it from time to time, because.... I don't know why. Something changes, distro is updated, anything will break the script. Sometimes. Or partially.

  • @rolandchristensen5889
    @rolandchristensen5889 3 роки тому

    could you make a video on pwndb and tools like it?

  • @kbhatt2762
    @kbhatt2762 3 роки тому

    Interesting. Loved it.

  • @lawjv
    @lawjv 3 роки тому

    Seriously Teach me more!!

  • @123gostly
    @123gostly 3 роки тому

    Macbook named Dell-3?

  • @faizantanveer1925
    @faizantanveer1925 Рік тому

    I forget my Snapchat my eyes password, can i find this with Sherlock or any other way, kindly help me

  • @incaon555
    @incaon555 3 роки тому

    Very nice thanks !

  • @SteepVisions
    @SteepVisions 3 роки тому +2

    0:24 OMG

  • @_DeProgrammer
    @_DeProgrammer 3 роки тому +2

    You Blinked!!! Thanks for another great tip

  • @realhomy
    @realhomy 3 роки тому

    lets go another upload

  • @Thomas72B
    @Thomas72B 3 роки тому

    Windows 10 Linux Subsystem is crap ! Bash script not working "echo" work but nothing else works

  • @vijaySingle143
    @vijaySingle143 3 роки тому

    Kody doesn't blink eyes

  • @spanish_with_chris
    @spanish_with_chris 3 роки тому

    Thanks!

  • @SmashPhysical
    @SmashPhysical 3 роки тому +2

    Thank you, great information! Could definitely do without the music though...

  • @mrztack55
    @mrztack55 3 роки тому

    Awesome video

  • @danielluigi139
    @danielluigi139 3 роки тому

    Hy.
    I Lear a lot whith your video, (I'm Italian) so sorry 4 my righting.
    Well can you tell me if termux is a good things to learn.
    Thank's anyway... You are really brave I mean how you teach.

    • @vicfic_
      @vicfic_ 3 роки тому

      Dude, termux is just a terminal emulator. You don't "learn termux", you learn to use the linux command line.
      Most commands in linux are the same in termux because both use bash.

    • @vicfic_
      @vicfic_ 3 роки тому

      @SALTINBANK he said TERMUX not TMUX. Termux is android terminal emulator.

  • @JNET_Reloaded
    @JNET_Reloaded 3 роки тому

    lol wtf expect "assword:" ???

  • @Michael_Kerstein
    @Michael_Kerstein 3 роки тому

    Can't believe you use a Mac

  • @mynameisjeff1692
    @mynameisjeff1692 3 роки тому

    I was here 1 minutes after the video post

  • @hackerstech4025
    @hackerstech4025 3 роки тому

    Bring free hcking course

  • @rileyhampson
    @rileyhampson 3 роки тому +1

    Epic

  • @pashtoonlinezdakra9595
    @pashtoonlinezdakra9595 3 роки тому

    Sir How to hack fb traget account

  • @kaitycodes
    @kaitycodes 3 роки тому +1

    Bash | 🙅🏽‍♀️
    Expect | 🤦🏽‍♀️
    Bash + Expect | 😌😏😎

  • @cyberrock9018
    @cyberrock9018 3 роки тому

    #! bin/bash
    echo "Kody is the goat"

  • @nya0783
    @nya0783 3 роки тому

    Pog

    • @nikolas8741
      @nikolas8741 3 роки тому

      That's the second time I read that on UA-cam today. What that means?

    • @garcand
      @garcand 3 роки тому +1

      Its usually "Person otherthan grunt"..military term.

  • @realhomy
    @realhomy 3 роки тому

    KODY K...

  • @realhomy
    @realhomy 3 роки тому

    YESSIR

  • @Anonymous-eq3eb
    @Anonymous-eq3eb 3 роки тому

    Da

  • @HackerboySoubhik
    @HackerboySoubhik 3 роки тому

    Please make a tutorial on how to remotely access kali linux machine from android....
    Please.....

    • @vicfic_
      @vicfic_ 3 роки тому

      You can be hacked if you set up any kind of remote access. That is the reason kali doesn't enable remote access by default.
      If you don't care, just install ssh-server on kali and ssh client on android using something like termux.

  • @GeekBatman
    @GeekBatman 3 роки тому

    ssh -t username@host 'reboot' works fine for me.

  • @ethanshay7819
    @ethanshay7819 3 роки тому

    First

  • @SimSpark1
    @SimSpark1 3 роки тому

    are you single;-)????

  • @calebwendi8471
    @calebwendi8471 3 роки тому

    I want to hack WiFi without adapter and monitor mode .

    • @vicfic_
      @vicfic_ 3 роки тому

      same problem here. sadly there is no way :(

  • @Turjak_art
    @Turjak_art 2 роки тому

    I stopped watching as he said "I'm using a Mac computer"! +dislike

    • @undeze
      @undeze Рік тому

      Snob. Haha 😊

  • @GooogleGoglee
    @GooogleGoglee 3 роки тому

    Answer to this comment with your customized script!