working on it ...

Filters

Explore Public Snippets

Sort by

Found 4,331 snippets matching: ssh

    public by lbottaro  7138  2  8  0

    Setting a Clearcase view and run command remotely via SSH

    This bash script allows user to set a IBM Rational Clearcase view on a remote machine and run a script on it via ssh.
    #!/bin/tcsh -e
    # Script to execute a cmd or script remotely via ssh on a target machine
    
    echo Executing make script: $0
    echo Make targets: \"$*\"
    echo Working directory: $PWD
    set _CLEARCASE_VIEW = `cleartool pwv -short -setview`
    echo Set view: "$_CLEARCASE_VIEW"
    
    # check build server
    if ( $?BUILDHOST == 0 ) then
      echo "Error: variable BUILDHOST not set, build aborted."
      exit -1
    endif
    
    # check clearcase view
    if ( "$_CLEARCASE_VIEW" == "** NONE **" ) then
      echo "Error: ClearCase view not set, build aborted."
      exit -1
    endif
    
    # script parameters check...
    if ( "$1" == "" ) then
      echo "Error: missing 1st param!"
      echo "Eg: ./myscript par1 par2"
      exit -1
    endif  
    
    if ( "$1" == "" ) then
      echo "Error: missing 1st param!"
      echo "Eg: ./myscript par1 par2"
      exit -1
    endif  
    
    # create remote script
    set remote_script=$PWD/.${USER}@${HOST}-`basename $0`
    rm -rf $remote_script
    echo "myscript $1 $2" > $remote_script
    echo "rm -rf $remote_script" >> $remote_script
    chmod a+x $remote_script
    
    # exec script in the current view on the build server
    echo Executing build script: $remote_script
    echo via SSH on Host: $BUILDHOST
    echo -----
    cat $remote_script
    echo -----
    echo Starting remote build...
    ssh $BUILDHOST cleartool setview -exec $remote_script $_CLEARCASE_VIEW
    

    public by lbottaro  3349  4  7  0

    Remote execution of command on clearcase view via ssh

    This bash script allows to execute a dynamic command on a remote machine, using ssh authentication within a Clearcase dynamic view. Note that the command to run in generated by some variables and it's passed to ssh via a file. The cat command will input the command into remote shell to be executed on another machine. You can find also th
    my_dest_path="/some/path/"
    # This return current directory
    currentDir=`pwd`
    # This return the CLearcase view name
    currentView=`cleartool pwv -s`
    echo "Setting view: ${currentView} on remote machine"
    # This is the command to execute
    cmd="cleartool setview -exec \"echo currentDir=${currentDir}; echo my_dest_path=${my_dest_path}; cd ${currentDir}; cp -an data/* ${my_dest_path}; hostname\" ${currentView}"
    echo "cmd=${cmd}"
    # This is a tmp file where to save the command
    file=.`hostname`-remote-cmd.txt
    rm -f ${file}
    # Create a tmp file to save the command to execute
    echo ${cmd} > ${file}
    # This run the command on <remoteMachine>
    /usr/bin/time -f "%E" -o ${my_platform_label}.time ssh -Y <remoteMachine> 'bash -s' < ${file}

    public by lbottaro  2250  0  5  0

    Linux SSH remote shell cmd

    This command allows to execute a cmd or script in a xterm shell remotely on another machine via ssh. Xterm will popup showing the cmd execution
    ssh -Y <HOSTNAME> xterm -bg DarkBlue -fg white -geometry 128x24 -sl 200000 -hold -T <TERM_TITLE> -exec '<CMD_or_SCRIPT>'

    public by sh1nu11bi  3614  0  4  0

    SSL / SSH Private Key Passphase Cracker v1.0

    SSL / SSH Private Key Passphase Cracker v1.0 : gistfile1.txt
    #!/bin/bash
    ################################################################################
    #                ____                     _ __                                 #
    #     ___  __ __/ / /__ ___ ______ ______(_) /___ __                           #
    #    / _ \/ // / / (_-</ -_) __/ // / __/ / __/ // /                           #
    #   /_//_/\_,_/_/_/___/\__/\__/\_,_/_/ /_/\__/\_, /                            #
    #                                            /___/ team                        #
    #                                                                              #
    # ssl-crack.sh - wordlist-based encrypted SSL and SSH Private Key Passphase    #
    # Cracker                                                                      #
    #                                                                              #
    # FILE                                                                         #
    # ssl-crack.sh                                                                 #
    #                                                                              #
    # DATE                                                                         #
    # 2013-08-31                                                                   #
    #                                                                              #
    # DESCRIPTION                                                                  #
    # Loads a wordlist file into memory and reveals the password for the RSA       #
    # encrypted private SSL / SSH key                                              #
    #                                                                              #
    # AUTHOR                                                                       #
    # TheXero                                                                      #
    #                                                                              #
    ################################################################################
    
    
    WORDLIST='/home/thexero/lists/passwords.txt'
    
    
    echo """
                                ____                     _ __                                 
                     ___  __ __/ / /__ ___ ______ ______(_) /___ __                           
                    / _ \/ // / / (_-</ -_) __/ // / __/ / __/ // /                           
                   /_//_/\_,_/_/_/___/\__/\__/\_,_/_/ /_/\__/\_, /                            
                                                            /___/ team                        
    
         *********************************************************************
                     SSL / SSH Private Key Passphase Cracker v1.0                
         *********************************************************************
    
    """
    
    if [ -z "$1" ]
    then 
        echo "Enter path to encrypted SSL / SSH private key"
        read KEYFILE
    else
        KEYFILE=$1
    fi
    
    for PASSWORD in $(cat $WORDLIST);
    
    do
        
        if [[ -n $(echo -n $PASSWORD | openssl rsa -in $KEYFILE -passin stdin 2>&1 |
            grep -v unable |grep -v error) ]]  
            then
            echo -e 'Password for SSL / SSH Key is:' $PASSWORD 
            echo -n $PASSWORD | openssl rsa -in $KEYFILE -passin stdin 2>&1
            
            exit
        fi
    
    done
    
    

    public by r_walker  2579  3  5  0

    ipython server over ssh

    // start ipython on a remote server; bind a local client port to the server's ipython port
    // over ssh
    // SOURCE: http://wisdomthroughknowledge.blogspot.com/2012/07/accessing-ipython-notebook-remotely.html
    
    // server
    ipython notebook --no-browser --port=7000
    
    // clients
    ssh -N -f -L localhost:6000:localhost:7000 user@server
    
    

    public by maholtz  2228  1  6  0

    shell Komandos über ssh ausführen

    Da $(pwd) schon bei der Übergabe aufgelöst werden würde, wird das in einer Variablen übergeben. Somit wird $(pwd) erst auf dem Server ausgeführt. Das ganze kann in einem Skript ablaufen...
    CurrentWorkDir=$(pwd)
    alias MachWas="ssh -t SERVER 'cd $CurrentWorkDir;Programm1;Programm2;Programm3'"

    public by Aysad Kozanoglu  870  7  3  0

    iptable script enable http https ssh 222001 postfix&dovecot imp

    iptable script enable http https ssh 222001 postfix&dovecot imp: iptable-script.sh
     #!/bin/sh
    
    # iptables script generated 2016-03-03
    # http://www.mista.nu/iptables
    
    
    
    IPT="/sbin/iptables"
    
    
    # Flush old rules, old custom tables
    $IPT --flush
    $IPT --delete-chain
    
    # Set default policies for all three default chains
    $IPT -P INPUT DROP
    
    $IPT -P FORWARD DROP
    $IPT -P OUTPUT ACCEPT
    
    # Enable free use of loopback interfaces
    $IPT -A INPUT -i lo -j ACCEPT
    $IPT -A OUTPUT -o lo -j ACCEPT
    
    # All TCP sessions should begin with SYN
    $IPT -A INPUT -p tcp ! --syn -m state --state NEW -s 0.0.0.0/0 -j DROP
    
    
    # Accept inbound TCP packets
    $IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    $IPT -A INPUT -p tcp --dport 22001 -m state --state NEW -s 0.0.0.0/0 -j ACCEPT
    $IPT -A INPUT -p tcp --dport 80 -m state --state NEW -s 0.0.0.0/0 -j ACCEPT
    $IPT -A INPUT -p tcp --dport 443 -m state --state NEW -s 0.0.0.0/0 -j ACCEPT
    #postfix dovecot ports
    $IPT -A INPUT -p tcp --dport 143 -m state --state NEW -s 0.0.0.0/0 -j ACCEPT
    $IPT -A INPUT -p tcp --dport 993 -m state --state NEW -s 0.0.0.0/0 -j ACCEPT
    $IPT -A INPUT -p tcp --dport 995 -m state --state NEW -s 0.0.0.0/0 -j ACCEPT
    $IPT -A INPUT -p tcp --dport 465 -m state --state NEW -s 0.0.0.0/0 -j ACCEPT
    $IPT -A INPUT -p tcp --dport 25 -m state --state NEW -s 0.0.0.0/0 -j ACCEPT
    
    # Accept inbound ICMP messages
    $IPT -A INPUT -p ICMP --icmp-type 8 -s 0.0.0.0/0 -j ACCEPT
    $IPT -A INPUT -p icmp -m icmp --icmp-type 8 -m limit --limit 1/second -j ACCEPT
    
    
    
    #LOGGING
    
    
    

    public by Jaya Wijono  1486  0  3  0

    Building SSH Key management tool with Elixir

    Building SSH Key management tool with Elixir: Building SSH Key management tool with Elixir.md
    Building SSH Key management tool with Elixir
    ===================
    
    ### Sipping the Elixir
    After being inspired by [David's talk on Elixir]() at Hardhat, we decided to try and build our own SSH public key management tool **PubKeys** in Elixir. We're delightful to report back that elixir is amazing and we've released the code source to open-source community at [Github](https://github.com/hardhatdigital/pub_keys). 
    
    Things we love about Elixir:
    * Writing codes in functional programming style encourage us to break the code into small chunks of functions.
    * Through the use of pipe operator `|>`, this makes the code much more readable, and elegant.
    * Pattern matching.
    * Documentation as first class citizen.
    
    ### Introducing PubKeys
    The purpose of the PubKeys is to enable the developers at Hardhat to easily manage user's SSH Key access to various servers from one main machine. The following are key functionalities of PubKeys:
    * Add a user into all the target machines.
    * Remove a user from all the target machines.
    * Add / remove a user from particular machines.
    
    ### How Pubkeys work
    PubKeys works by looking at the specified directory for the list of ssh keys files. These files are named after the IP Address remote server and contain all the user's SSH public keys that we want to sync to the remote machine. PubKeys parse those files to add / remove key, and then perform `scp` secure copy command to syncrhonize the ssh keys on the files with the remote server.
    
    ![concept](http://i.imgur.com/gzb8xe8.jpg)
    
    ### The potent Elixir
    ##### Main function
    Peeking inside the [code](https://github.com/hardhatdigital/pub_keys), we can see that the`main` function takes input arguments. Using Elixir's pattern matching, we can match the input arguents with the case defined and execute functions where it matches the condition.
    
    ![input](http://i.imgur.com/TPfw4VN.jpg)
    
    ```PubKeys_input
    def main(options) do
        path = files_path(Mix.env)
        files_list = System.cmd("ls", [path]) |> elem(0) |> String.split("\n")
        
        case options do
          ["--help"] -> IO.puts @instructions
          ["--deploy-all"] -> deploy_all(files_list, path)
          ["--add", ssh_key] -> add_user_key(ssh_key, files_list, path)
          ["--remove", ssh_key] -> remove_user_key(ssh_key, files_list, path)
          _ -> IO.puts "Unrecognized input.\n#{@instructions}"
        end
      end
    ```
    ##### Depolying to remote servers
    This function takes a list of ssh key files and a remote target path as argument inputs. 
    Through the use of the pipe operator `|>`, we can pass in the files list to the function to filter out any empty files, and then pass the result of this process to the next function that will scp the file to remote server.
    
    You can see that this process flow is akin to the process in an assembly line. a collection of objects is being passed to a function which in return pass the results to the next function. This is what makes Elixir with functional programming style more elegant compared to traditional imperative programming style.
    
    ![deploy-all](http://i.imgur.com/xi66DV8.jpg)
    
    ```PubKeys_deploy_all
    def deploy_all(files_list, path) do
        files_list
        |> Enum.reject(&empty?(&1))
        |> Enum.map(&scp_to_server(&1, path))
      end
    ```
    
    ##### Adding / removing a user
    The `add_user_key` and `remove_user_key` function takes 3 inputs: ssh_key, files_list, and path. Like the function `deploy_all`, this function pass the input from one function to another until the last function that will scp the file to remote server.
    
    These are functions in PubKeys for adding or removing a user:
    * Adding a user
    
    ![add key](http://i.imgur.com/YWnRV7A.jpg)
    
    ```PubKeys_add.ex
    def add_user_key(ssh_key, files_list, path) do
        files_list
        |> Enum.reject(&empty?(&1))
        |> Enum.map(&read_keys(&1, path))
        |> Enum.reject(&should_skip?(&1, ssh_key))
        |> Enum.map(&prepend_key(&1, ssh_key, path))
        |> Enum.map(&scp_to_server(&1, path))
      end
    ```
    
    * Removing a user
    
    ![delete key](http://i.imgur.com/PaZWK2k.jpg)
    
    ```PubKeys_remove.ex
    def remove_user_key(ssh_key, files_list, path) do
        files_list
        |> Enum.reject(&empty?(&1))
        |> Enum.map(&read_keys(&1, path))
        |> Enum.reject(&should_skip?(&1, ssh_key, :remove))
        |> Enum.map(&remove_key(&1, ssh_key, path))
        |> Enum.map(&scp_to_server(&1, path))
      end
    ```
    
    ### Documentation
    Elixir makes documentation as [first class citizen](http://elixir-lang.org/getting-started/mix-otp/docs-tests-and-pipelines.html#doctests). 
    With `Doctest`, one can easily  write a comment that document about what a function does and also provide a test within the example. this test can be integrated as part of the test suite when running `Mix test`.
    The following code snippet displays an example of doctest implementation. 
    
    ```Doc_example.ex
    @doc """
      Given an input of remote server's IP address, and the directory path to ssh key files, returns a tuple containing the ip address and a list of the ssh_keys
      ## Examples
          iex> path = PubKeys.Helper.files_path(:test)
          iex> PubKeys.read_keys("192.168.0.10", path)
          {"192.168.0.10", ["ssh-rsa ABCD123abcd test1@work", "ssh-rsa XYZ987abcd test2@work"]}
      """
     def read_keys(ip, path) do
      {:ok, content} = File.read("#{path}/#{ip}")
      filtered_keys = (String.split(content, "\n") |> Enum.reject(&empty?/1))
      {ip, filtered_keys}
    end
      ```
    With [Ex_doc](https://github.com/elixir-lang/ex_doc), we can easily generate documentation by running `mix docs`. The generated documenation is a very neat addition to doctest. An example of PubKeys generated documentation can be viewed here : [PubKeys Doc](http://hardhatdigital.github.io/pub_keys/PubKeys.html)
    
    ### Conclusion
    **PubKeys** is now deployed live in Hardhat's server and is our internal tool for managing user's SSH keys. The experience building this tool with Elixir has been a delightful one and a fresh approach in writting functional programming style. 
    
    Through this journey, we've learnt the potent of Elixir as a programming language. Having said that, we've only scratched half of Elixir's potency here. Elixir comes out of the box with concurent, distributed, and fault-tolerant properties. If you're interested in learning more about Elixir, we highly recommend to check out this [guide.](http://elixir-lang.org/learning.html)
    
    Elixir with it's functional programming style is very elegant and fun to write. The way how Elixir makes documentation as first class citizen with Doctest makes testing and documenting code much easier. We have a lot of fun building PubKeys with Elixir in Hardhat. Next we're looking at [Phoenix](http://www.phoenixframework.org/), a web framework written in Elixir. Stay tuned for the next post!
    
    

    public by lkonga  367  0  3  0

    Convert HTTPS github clones to use SSH

    Convert HTTPS github clones to use SSH: fix_github_https_repo.sh
    #/bin/bash
    #-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password
    
    REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(https://[^[:space:]]*).*#\1#p'`
    if [ -z "$REPO_URL" ]; then
      echo "-- ERROR:  Could not identify Repo url."
      echo "   It is possible this repo is already using SSH instead of HTTPS."
      exit
    fi
    
    USER=`echo $REPO_URL | sed -Ene's#https://github.com/([^/]*)/(.*).git#\1#p'`
    if [ -z "$USER" ]; then
      echo "-- ERROR:  Could not identify User."
      exit
    fi
    
    REPO=`echo $REPO_URL | sed -Ene's#https://github.com/([^/]*)/(.*).git#\2#p'`
    if [ -z "$REPO" ]; then
      echo "-- ERROR:  Could not identify Repo."
      exit
    fi
    
    NEW_URL="git@github.com:$USER/$REPO.git"
    echo "Changing repo url from "
    echo "  '$REPO_URL'"
    echo "      to "
    echo "  '$NEW_URL'"
    echo ""
    
    CHANGE_CMD="git remote set-url origin $NEW_URL"
    `$CHANGE_CMD`
    
    echo "Success"
    
    

    public by yourfriendcaspian  315  0  3  0

    SSH - SSL Cheatsheet

    SSH - SSL Cheatsheet: ssl-ssh-cheatsheet.txt
    1. Convert PEM into pub SSH key file:
    ssh-keygen -e -f amazon-ec2-key.pem >> amazon-ec2-key.pem.pub
    
    2. Generate a PEM from a SSH key: 
    openssl rsa -in my_tunneler -outform pem > my_tunneler.pem
    
    
    • Public Snippets
    • Channels Snippets