Python SSH Client - Paramiko. SSH with Python.

Поделиться
HTML-код
  • Опубликовано: 22 июл 2024
  • In this video, I go over how to create ssh sessions with Paramiko.
    👨‍💻 Join our Discord Community of DevOps Engineers: / discord
    ☕ Buy me a coffee: www.buymeacoffee.com/bradmorg
    📁 Code Available Here: devopslifecycle.com/lessons/1...
    📘 Chapters:
    0:00 What is Paramiko
    0:29 Creating SSH sessions and sending commands with paramiko
    5:22 Automating SSH commands to Multiple hosts
  • НаукаНаука

Комментарии • 63

  • @TheModsRE4
    @TheModsRE4 3 года назад +1

    Very useful and easy to understand. I had to use the passphrase instead of password to make it works, but in general, everything was the same, THANKS A LOT!

  • @mav29
    @mav29 2 года назад

    great job, perfect example very clear, concise easy to learn. well explained

  • @duanewalker8925
    @duanewalker8925 2 года назад +1

    Paramiko makes it really easy to connect to Linux servers and Cisco devices. I used to do this with Perl years ago but it was very frustrating. You had to tell the library the different prompts, etc. IOS and CatOS devices worked differently.

  • @Sparshchokra
    @Sparshchokra 2 года назад

    Hi Sir,
    Can you please specify how may I use this inspect() function to get knowledge about object?

  • @chriskeo392
    @chriskeo392 3 года назад +7

    Request: ssh basics/fundamentals. And it's use cases
    Would be great.

  • @chriskeo392
    @chriskeo392 3 года назад +2

    Sick content

  • @juanariza9093
    @juanariza9093 2 года назад

    How do I save command output to variables? I am not able to manipulate variables when assigning variables to output

  • @rishabhgupta7742
    @rishabhgupta7742 2 года назад

    Will this code work for connecting host with IPv6 address as well?
    If not what changes might be required.

  • @user-pw4cd4hw5e
    @user-pw4cd4hw5e Год назад

    It was so helpfull for me thank u very much

  • @anatoly_north2564
    @anatoly_north2564 2 года назад +1

    thx! you video my problem with Piramiko

  • @vishalmaurya972
    @vishalmaurya972 2 года назад

    Great Content. Could you please help me for SFTP using paramiko only the current data-1 files from Lan to remote server. I guess exec_command will work on remote server only. What if we want to run the command on out Local i.e. LAN files? please help.

  • @sandhuaditya4855
    @sandhuaditya4855 Год назад

    How do you keep the The shell to persist with these commands. Like your pulling the hostname, if you go ahead and navigate to a particular directory. And then in the next command You want to touch file .txt you will notice that the exec closed out and that you are not in the directory that You Navigate to do but are in the home directory again. You have to change the commands inside a single exec Is there any way around that

  • @preethiratnala3650
    @preethiratnala3650 Год назад

    I did same as you said but when I replace hostname with directory command 'ls -lrt' Its giving total 0 why its happening

  • @Zancb
    @Zancb 3 года назад +7

    Hi there. Thanks for the video. One quick suggestion: Do not connect to host machines as root.
    Connecting as root (or allowing root over ssh) is a gigantic security flaw. We (as in the IT community) should promote the use of connecting to a remote host as a specific user, rather than root.
    Thanks again! This is really cool stuff.

  • @robertofleitas2612
    @robertofleitas2612 6 месяцев назад

    Hello, how can I make an paramiko SSH connection to a SSH host, through remote desktop (RDP)?
    thank you.

  • @juanpe5144
    @juanpe5144 2 года назад

    Hello I have a duubt if I want send more command how I can do it?

  • @DavidCSaint
    @DavidCSaint 2 года назад

    This is great

  • @sophylong5940
    @sophylong5940 2 года назад

    can you help me with a code that actually download a file already uploaded in a remote server?

  • @andreygunz179
    @andreygunz179 2 года назад

    how do you run more then 1 command on 1 host for example a switch that needs password>cli>configure>hostname its been hell searching for a solution online

  • @thefamousdjx
    @thefamousdjx 2 года назад +1

    Any idea how you would then connect to a mysql database in that server? I cant find anything about this

    • @DevOpsJourney
      @DevOpsJourney  2 года назад

      You would connect to it the same way as if you were SSH'd into another server. Should just be able to run your sqlclient command to connect

  • @TheSibyjohn
    @TheSibyjohn 2 года назад

    please how long and big is this code?

  • @vibhorkumar8854
    @vibhorkumar8854 Год назад

    How to keep ssh alive for long running cmd on a remote server?
    I am getting socket timeout and buffed.timeout while running long running shell command on remote host.

    • @DevOpsJourney
      @DevOpsJourney  Год назад

      Timeouts would be on the serverside. Check the settings on the remote host ssh server service.

  • @seantellsit1431
    @seantellsit1431 Год назад

    I'm not sure what I'm doing wrong.... when I try to run the snippet at 1:30, I keep getting an error.
    "PermissionError: [Errno 13] Permission denied: 'C:/Users/seans/.ssh/known_hosts'
    I've launched python from an elevated command prompt, but no joy.

  • @ToshuMalhotraiitk
    @ToshuMalhotraiitk Год назад

    But how you get authenticated, you haven't supply password for root anywhere, have you already copied your public key to all nodes?

  • @shayelasharma1039
    @shayelasharma1039 11 месяцев назад

    thanks man

  • @prasadsankar3775
    @prasadsankar3775 2 года назад

    Thanks for the video. I have a question - How to change directory after SSHing the server?

  • @shristiagrawal2080
    @shristiagrawal2080 2 года назад

    How to open shell using this and see what's going on

  • @kennychavez8994
    @kennychavez8994 2 года назад

    I have a problem. It seems that the fingerprint of the server I was connecting to changed, but I can't get it to work again. It gives me this error:
    Traceback (most recent call last):
    File "C:\Users\user\Documents\update_automation\main3.py", line 12, in
    stdin, stdout, stderr = client.exec_command('hostname')
    File "C:\Users\user\Documents\update_automation\venv\lib\site-packages\paramiko\client.py", line 514, in exec_command
    chan.exec_command(command)
    File "C:\Users\user\Documents\update_automation\venv\lib\site-packages\paramiko\channel.py", line 72, in _check
    return func(self, *args, **kwds)
    File "C:\Users\user\Documents\update_automation\venv\lib\site-packages\paramiko\channel.py", line 257, in exec_command
    self._wait_for_event()
    File "C:\Users\user\Documents\update_automation\venv\lib\site-packages\paramiko\channel.py", line 1226, in _wait_for_event
    raise e
    File "C:\Users\user\Documents\update_automation\venv\lib\site-packages\paramiko\transport.py", line 2055, in run
    ptype, m = self.packetizer.read_message()
    File "C:\Users\user\Documents\update_automation\venv\lib\site-packages\paramiko\packet.py", line 459, in read_message
    header = self.read_all(self.__block_size_in, check_rekey=True)
    File "C:\Users\user\Documents\update_automation\venv\lib\site-packages\paramiko\packet.py", line 303, in read_all
    raise EOFError()
    EOFError

  • @francescoleo2167
    @francescoleo2167 2 года назад +1

    Hi, could you share the coding again ? Cus the link for Code Available is not available now🤕

    • @DevOpsJourney
      @DevOpsJourney  2 года назад

      Apologies, the website is back up now!

  • @joostvoncken950
    @joostvoncken950 Год назад

    isnt the autoaddPolicy vulnerable for Man in the middle attacks?

    • @DevOpsJourney
      @DevOpsJourney  Год назад

      If you are in a more secure environment you could add to known hosts manually

  • @saruthecreator2823
    @saruthecreator2823 Год назад

    but does paramiko support ssh multiplexing ? if number of sessions are running , just like ssh natively supports , please help

    • @DevOpsJourney
      @DevOpsJourney  Год назад

      hey there, as of my knowledge, it does not support SSH multiplexing... but I could be wrong

    • @saruthecreator2823
      @saruthecreator2823 Год назад

      @@DevOpsJourney thanks for the reply , but do you know anything which could ease up or does have the same kind of functionality, i am working on a project which involves multiple ssh to get some of the system metrics from the os , but i cant use any of monitoring tools , i can only use ssh any help i would really appreciate thanks

  • @simoneonorato1223
    @simoneonorato1223 3 года назад +1

    Sorry but how do you tell your program where the private key is stored on ur pc?

    • @DevOpsJourney
      @DevOpsJourney  3 года назад +1

      Hey Simone. Use the below function and specify the path:
      load_system_host_keys(filename='path/to/hostkeys')
      I hope that helps!

    • @simoneonorato1223
      @simoneonorato1223 3 года назад

      @@DevOpsJourney Thanks a lot!!!!

  • @thulasisunny1951
    @thulasisunny1951 Год назад

    Hi, When I run the command same you given i am getting this error "Could not chdir to home directory /home/kyndrylssh: Permission denied" , can you think is that SSH connected ??? how can we confirm that...

    • @DevOpsJourney
      @DevOpsJourney  Год назад

      Try a 'hostname'. That's how I confirm

    • @thulasisunny1951
      @thulasisunny1951 Год назад

      @@DevOpsJourney u mean command 'hostname'? I am getting something for that also

  • @davipires2999
    @davipires2999 Год назад +1

    Can I use the paramiko to run a script in the vm that the ssh server is installed?

    • @DevOpsJourney
      @DevOpsJourney  Год назад

      Yup!

    • @davipires2999
      @davipires2999 Год назад

      @@DevOpsJourney the machine that the ssh server installed can be windows? Everything Will work fine on windows?

    • @DevOpsJourney
      @DevOpsJourney  Год назад

      @@davipires2999 yes you can use paramiko to ssh into a windows box

    • @davipires2999
      @davipires2999 Год назад

      @@DevOpsJourney thanks mate, i'll try this tomorrow in my internship!!!

  • @francis.joseph
    @francis.joseph Год назад

    How to get the known hosts file created

    • @DevOpsJourney
      @DevOpsJourney  Год назад

      should be in ~/.ssh/known_hosts, or c:\users\\.ssh\known_hosts

  • @enriquecordero6163
    @enriquecordero6163 3 года назад

    Is possible to do a sudo to another user? , ssh with brad and then sudo to tomcat?

  • @realkgsite
    @realkgsite 2 года назад

    How to stay on server in comand-line?

    • @stfu_anderr
      @stfu_anderr 2 года назад +1

      use while and instead of 'hostname' enter 'input()'

  • @varadmulay
    @varadmulay Год назад

    what is in the "known_hosts" file ?

    • @DevOpsJourney
      @DevOpsJourney  Год назад

      Server fingerprints. That prompt that comes up when you ssh into a new server asking about if you trust the finger print - when you do it's saved to the known hosts file. If you try to connect to a server with the same IP but the fingerprint has changed, ssh will warn you that something has changed

    • @varadmulay
      @varadmulay Год назад

      @@DevOpsJourney in what format ?
      Ip, type, pkey?

  • @igorfagundes2177
    @igorfagundes2177 3 года назад +3

    3:53 As a robot, I got offended