Skip to content

Instantly share code, notes, and snippets.

@stiakov
Last active September 6, 2019 17:59
Show Gist options
  • Select an option

  • Save stiakov/7c06480321adec26a3a1d1e7df428320 to your computer and use it in GitHub Desktop.

Select an option

Save stiakov/7c06480321adec26a3a1d1e7df428320 to your computer and use it in GitHub Desktop.

Revisions

  1. Santiago Torres revised this gist Sep 6, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion auto_login.md
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@ According to your $SHELL, use the proper file, in my case I'm using **ZSH** so I

    1. Export your password as an environment variable:

    `echo "$ export hid_pass='p455word'"`
    `$ echo "export hid_pass='p455word'"`

    2. Update your $Shell after every modification:

  2. Santiago Torres revised this gist Sep 6, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion auto_login.md
    Original file line number Diff line number Diff line change
    @@ -71,7 +71,7 @@ Create an alias to run the connection within preset args.

    1. Add your alias to your $SHELL (.zshrc / .bashrc):

    * `$ echo "alias mycon='~/my_connection.exp 192.168.0.100 root $hid_pass'"`
    `$ echo "alias mycon='~/my_connection.exp 192.168.0.100 root $hid_pass'"`

    2. Don't forget to update the $SHELL after every modification:

  3. Santiago Torres revised this gist Sep 6, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions auto_login.md
    Original file line number Diff line number Diff line change
    @@ -75,8 +75,8 @@ Create an alias to run the connection within preset args.

    2. Don't forget to update the $SHELL after every modification:

    * `$ exec $SHELL` or `$ source ~/.zshrc`
    `$ exec $SHELL` or `$ source ~/.zshrc`

    3. Call the connection using your alias, and wait until the connection is done:

    * `$ mycon`
    `$ mycon`
  4. Santiago Torres revised this gist Sep 6, 2019. 1 changed file with 13 additions and 13 deletions.
    26 changes: 13 additions & 13 deletions auto_login.md
    Original file line number Diff line number Diff line change
    @@ -10,11 +10,11 @@ You need **expect** scripting language to run this task.

    # Setup

    1 Create a file that will store your _expect script_:
    1. Create a file that will store your _expect script_:

    `$ touch ~/my_connection.exp`

    2 Edit your file in your favorite editor:
    2. Edit your file in your favorite editor:

    ```
    #!/usr/bin/expect
    @@ -36,11 +36,11 @@ send "$password\r";
    interact
    ```

    3 Modifiy permissions to your _expect script_:
    3. Modifiy permissions to your _expect script_:

    `$ chmod +x ~/my_connection.exp`

    4 Run your script using arguments like this, use your own args:
    4. Run your script using arguments like this, use your own args:

    `$ ~/my_connection.exp 192.198.0.100 root p455w0rd`

    @@ -53,30 +53,30 @@ Avoid to expose your password exporting it from your **.zshrc** / **.bashrc**.

    According to your $SHELL, use the proper file, in my case I'm using **ZSH** so I'll edit my **~/.zshrc**.

    1 Export your password as an environment variable:
    1. Export your password as an environment variable:

    `echo "$ export hid_pass='p455word'"`

    2 Update your $Shell after every modification:
    2. Update your $Shell after every modification:

    `$ exec $SHELL` or `$ source ~/.zshrc`

    3 Use your script without exposing your password:
    3. Use your script without exposing your password:

    `$ ~/my_connection.exp 192.168.0.100 root $hid_pass`

    ## Run your connection with a couple keystrokes

    Create an alias to run the connection within preset args.

    1 Add your alias to your $SHELL (.zshrc / .bashrc):
    1. Add your alias to your $SHELL (.zshrc / .bashrc):

    `$ echo "alias mycon='~/my_connection.exp 192.168.0.100 root $hid_pass'"`
    * `$ echo "alias mycon='~/my_connection.exp 192.168.0.100 root $hid_pass'"`

    2 Don't forget to update the $SHELL after every modification:
    2. Don't forget to update the $SHELL after every modification:

    `$ exec $SHELL` or `$ source ~/.zshrc`
    * `$ exec $SHELL` or `$ source ~/.zshrc`

    3 Call the connection using your alias, and wait until the connection is done:
    3. Call the connection using your alias, and wait until the connection is done:

    `$ mycon`
    * `$ mycon`
  5. Santiago Torres revised this gist Sep 6, 2019. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions auto_login.md
    Original file line number Diff line number Diff line change
    @@ -2,19 +2,19 @@

    ## Requirements

    You need `expect` scripting language to run this task
    You need **expect** scripting language to run this task.

    - In debian based distros run `$ sudo apt install expect`
    - In debian based distros run: `$ sudo apt install expect`

    - In MacOs `brew install expect`
    - In MacOS: `$ brew install expect`

    # Setup

    1 Create a file that will store your _expect script_.
    1 Create a file that will store your _expect script_:

    `$ touch ~/my_connection.exp`

    2 Edit your file in your favorite editor.
    2 Edit your file in your favorite editor:

    ```
    #!/usr/bin/expect
    @@ -36,7 +36,7 @@ send "$password\r";
    interact
    ```

    3 Modifiy permissions to your _expect script_
    3 Modifiy permissions to your _expect script_:

    `$ chmod +x ~/my_connection.exp`

    @@ -51,11 +51,11 @@ interact

    Avoid to expose your password exporting it from your **.zshrc** / **.bashrc**.

    According to your $SHELL, use the proper file, in my case I'm using **ZSH** so I'll edit my **~/.zshrc**
    According to your $SHELL, use the proper file, in my case I'm using **ZSH** so I'll edit my **~/.zshrc**.

    1 Export your password as an environment variable:

    `echo "export hid_pass='p455word'"`
    `echo "$ export hid_pass='p455word'"`

    2 Update your $Shell after every modification:

    @@ -73,7 +73,7 @@ Create an alias to run the connection within preset args.

    `$ echo "alias mycon='~/my_connection.exp 192.168.0.100 root $hid_pass'"`

    2 Don't forget to update your $SHELL after every modification:
    2 Don't forget to update the $SHELL after every modification:

    `$ exec $SHELL` or `$ source ~/.zshrc`

  6. Santiago Torres revised this gist Sep 6, 2019. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions auto_login.md
    Original file line number Diff line number Diff line change
    @@ -49,34 +49,34 @@ interact

    ## Hide your pass

    Avoid to expose your password exporting it from your .zshrc / .bashrc
    Avoid to expose your password exporting it from your **.zshrc** / **.bashrc**.

    According to your shell, use the proper file, in my case I'm using **ZSH** so I'll edit my **~/.zshrc**
    According to your $SHELL, use the proper file, in my case I'm using **ZSH** so I'll edit my **~/.zshrc**

    1 Export your password to an environment constant
    1 Export your password as an environment variable:

    `echo "export hid_pass='p455word'"`

    2 Update your $Shell after every modification
    2 Update your $Shell after every modification:

    `$ exec $SHELL` or `$ source ~/.zshrc`

    3 Use your script without exposing your password
    3 Use your script without exposing your password:

    `$ ~/my_connection.exp 192.168.0.100 root $hid_pass`

    ## Run your connection with a couple keystrokes

    Create an alias to run the connection within preset args
    Create an alias to run the connection within preset args.

    1 Add your alias to your $Shell (.zshrc / .bashrc)
    1 Add your alias to your $SHELL (.zshrc / .bashrc):

    `$ echo "alias mycon='~/my_connection.exp 192.168.0.100 root $hid_pass'"`

    2 Don't forget to update your $Shell after every modification
    2 Don't forget to update your $SHELL after every modification:

    `$ exec $SHELL` or `$ source ~/.zshrc`

    3 Call the connection using your alias, and wait until the connection is done
    3 Call the connection using your alias, and wait until the connection is done:

    `$ mycon`
  7. Santiago Torres revised this gist Sep 6, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion auto_login.md
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@ According to your shell, use the proper file, in my case I'm using **ZSH** so I'

    1 Export your password to an environment constant

    `echo "alias hid_pass='p455word'"`
    `echo "export hid_pass='p455word'"`

    2 Update your $Shell after every modification

  8. Santiago Torres revised this gist Sep 6, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions auto_login.md
    Original file line number Diff line number Diff line change
    @@ -78,4 +78,5 @@ Create an alias to run the connection within preset args
    `$ exec $SHELL` or `$ source ~/.zshrc`

    3 Call the connection using your alias, and wait until the connection is done

    `$ mycon`
  9. Santiago Torres revised this gist Sep 6, 2019. 1 changed file with 16 additions and 14 deletions.
    30 changes: 16 additions & 14 deletions auto_login.md
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,20 @@
    #Automatize your remote logins through ssh
    # Automatize your remote logins through ssh

    ##Requirements
    ## Requirements

    You need `expect` to run this task
    You need `expect` scripting language to run this task

    - In debian based distros run `$ sudo apt install expect`

    - In MacOs `brew install expect`

    # Setup

    Create a file that will store your _expect script_.
    1 Create a file that will store your _expect script_.

    - `$ touch ~/my_connection.exp`
    - Edit your file in your favorite editor.
    `$ touch ~/my_connection.exp`

    2 Edit your file in your favorite editor.

    ```
    #!/usr/bin/expect
    @@ -35,14 +36,15 @@ send "$password\r";
    interact
    ```

    - Modifiy permissions to your _expect script_
    3 Modifiy permissions to your _expect script_

    `$ chmod +x ~/my_connection.exp`

    - Run your script using arguments like this, use your own args:
    4 Run your script using arguments like this, use your own args:

    `$ ~/my_connection.exp 192.198.0.100 root p455w0rd`


    # Customizing (Optional)

    ## Hide your pass
    @@ -51,29 +53,29 @@ Avoid to expose your password exporting it from your .zshrc / .bashrc

    According to your shell, use the proper file, in my case I'm using **ZSH** so I'll edit my **~/.zshrc**

    - Export your password to an environment constant
    1 Export your password to an environment constant

    `echo "alias hid_pass='p455word'"`

    - Update your $Shell after every modification
    2 Update your $Shell after every modification

    `$ exec $SHELL` or `$ source ~/.zshrc`

    - Use your script without exposing your password
    3 Use your script without exposing your password

    `$ ~/my_connection.exp 192.168.0.100 root $hid_pass`

    ## Run your connection with a couple keystrokes

    Create an alias to run the connection within preset args

    - Add your alias to your $Shell (.zshrc / .bashrc)
    1 Add your alias to your $Shell (.zshrc / .bashrc)

    `$ echo "alias mycon='~/my_connection.exp 192.168.0.100 root $hid_pass'"`

    - Don't forget to update your $Shell after every modification
    2 Don't forget to update your $Shell after every modification

    `$ exec $SHELL` or `$ source ~/.zshrc`

    - Call the connection using your alias, and wait until the connection is done
    3 Call the connection using your alias, and wait until the connection is done
    `$ mycon`
  10. Santiago Torres revised this gist Sep 6, 2019. 1 changed file with 36 additions and 1 deletion.
    37 changes: 36 additions & 1 deletion auto_login.md
    Original file line number Diff line number Diff line change
    @@ -41,4 +41,39 @@ interact

    - Run your script using arguments like this, use your own args:

    `$ ~/my_connection.exp 192.198.0.100 root p455w0rd`
    `$ ~/my_connection.exp 192.198.0.100 root p455w0rd`

    # Customizing (Optional)

    ## Hide your pass

    Avoid to expose your password exporting it from your .zshrc / .bashrc

    According to your shell, use the proper file, in my case I'm using **ZSH** so I'll edit my **~/.zshrc**

    - Export your password to an environment constant

    `echo "alias hid_pass='p455word'"`

    - Update your $Shell after every modification

    `$ exec $SHELL` or `$ source ~/.zshrc`

    - Use your script without exposing your password

    `$ ~/my_connection.exp 192.168.0.100 root $hid_pass`

    ## Run your connection with a couple keystrokes

    Create an alias to run the connection within preset args

    - Add your alias to your $Shell (.zshrc / .bashrc)

    `$ echo "alias mycon='~/my_connection.exp 192.168.0.100 root $hid_pass'"`

    - Don't forget to update your $Shell after every modification

    `$ exec $SHELL` or `$ source ~/.zshrc`

    - Call the connection using your alias, and wait until the connection is done
    `$ mycon`
  11. Santiago Torres created this gist Sep 6, 2019.
    44 changes: 44 additions & 0 deletions auto_login.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #Automatize your remote logins through ssh

    ##Requirements

    You need `expect` to run this task

    - In debian based distros run `$ sudo apt install expect`

    - In MacOs `brew install expect`

    # Setup

    Create a file that will store your _expect script_.

    - `$ touch ~/my_connection.exp`
    - Edit your file in your favorite editor.

    ```
    #!/usr/bin/expect
    set timeout 5
    set ip [lindex $argv 0]
    set user [lindex $argv 1]
    set password [lindex $argv 2]
    spawn ssh "$user\@$ip"
    expect "Password:"
    send "$password\r";
    interact
    ```

    - Modifiy permissions to your _expect script_

    `$ chmod +x ~/my_connection.exp`

    - Run your script using arguments like this, use your own args:

    `$ ~/my_connection.exp 192.198.0.100 root p455w0rd`