IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » ssh The latest public ssh snipts.

showing 1-20 of 63 snipts for ssh
  • ssh .net
    using Tamir.SharpSsh;  //cargar la librería de Tamir en este caso es la que yo compilé
    
    public static string ref_server_cuentas = "192.168.1.1";        //la dirección ip del servidor unix/linux
    public static string ref_server_cuentas_usr = "root";             //el usuario con el que deseamos conectarnos mediante SSH (verificar que tenemos permisos) recomiendo no usar root hacer mejor un usuario que pueda ejecutar useradd, chpasswd2 y userdel solamente
    public static string ref_server_cuentas_pwd = "claveroot"; //la contraseña del servidor unix/linux
    
    public static string cambioClaveUnix(String usuario, String Contrasena)
    {
    //CAMBIAR CONTRASEÑA
    try
    {
    
    //abrimos la conexión con las variable globales de servidor
    SshExec exec = new SshExec(ref_server_cuentas, ref_server_cuentas_usr);
    exec.Password = ref_server_cuentas_pwd;
    exec.Connect();
    int b = 0;
    while (b == 0)
    {
    exec.RunCommand("sudo chpasswd2 " + usuario + " " + contrasena);   //ejecutamos el chpasswd2, el while es necesario porque los servidores tardan un poco en responder
    b = 1;
    
    }
    exec.Close();
    return "1";
    }
    catch (Exception e)
    {
    return e.Message;
    }
    }
    
    
    /// Permite crear un nuevo usuario en Unix
    public static string nuevoUsuarioUnix(String usuario, String Contrasena, String nombre, String id, String grupo, String ruta)
    {
    try
    {
    
    //abrimos la conexión con las variables globales de servidor
    
    SshExec exec = new SshExec(ref_server_cuentas, ref_server_cuentas_usr, ref_server_cuentas_pwd);
    exec.Connect();
    //ejecutamos el useradd con la variable grupo -g que es el grupo de unix donde debe quedar el usuario, la variable -s que es para indicar si les vamos a dar bash o no a los usuarios en mi caso no hay bach solo rssh,
    
    // -c son los comentarios, en mi caso decidí guardar el nombre completo del usuario verlo mejor en linux, el id también lo guardé es el código de usuario en mi sistema, y por último el -k que es el skel osea el nombre de usuario final uso la variable "usuario"
    
    exec.RunCommand("sudo useradd -g " + grupo + " -d " + ruta + usuario + " -s /usr/bin/rssh -c \"" + nombre + "," + id.TrimEnd() + "\" -m -k /etc/skel " + usuario);
    //Después de crear el usuario con useradd el usuario queda sin contraseña, entonces ejecuto chpasswd2 inmediatamente para cambiarla por la que recibí por parámetro
    
    exec.RunCommand("sudo chpasswd2 " + usuario + " " + Contrasena);
    exec.Close();
    return "1";
    }
    catch (Exception ex)
    {
    return ex.Message;
    }
    
    }
    
    
    /// <summary>
    /// Permite Borrar un usuario en unix
    public static string borrarUsuarioUnix(String usuario)
    {
    try
    {
    
    // BORRAR USUARIO  este no podía faltar con esta función mediante userdel en linux borramos usuarios
    SshExec exec = new SshExec(ref_server_cuentas, ref_server_cuentas_usr, ref_server_cuentas_pwd);
    exec.Connect();
    escribirLog("sudo userdel -r " + usuario);
    exec.RunCommand("sudo userdel -r " + usuario);
    exec.Close();
    return "1";
    }
    catch (Exception ex)
    {
    return ex.Message;
    
    }
    
    }
    

    copy | embed

    0 comments - tagged in  posted by anmezaf on Jul 22, 2010 at 3:17 a.m. EDT
  • Kill an unresponsive ssh session
    RET ~.
    

    copy | embed

    0 comments - tagged in  posted by febeling on Apr 28, 2010 at 3:34 a.m. EDT
  • enable/disable SSH X11 forwarding
    #!/bin/bash
    
    SSHD_CONFIG=/etc/ssh/sshd_config
    SSH_SVC=/etc/init.d/sshd
    
    v=`grep -m 1 -e "X11Forwarding" ${SSHD_CONFIG} | awk '{ if( $0 ~ /^#/ ) print "no"; else print $2; }'`
    
    enabled=0;
    
    if [ ${v} == 'yes' ]; then
            enabled=1;
    fi
    
    case "$1" in
      enable)
            if [ ${enabled} -eq 0 ]; then
                    sed -i 's/[#]*X11Forwarding[ ]*[a-z]*/X11Forwarding yes/' ${SSHD_CONFIG}
                    ${SSH_SVC} restart
            else
                    echo "already enabled"
            fi
            ;;
      disable)
            if [ ${enabled} -ne 0 ]; then
                    sed -i 's/[#]*X11Forwarding[ ]*[a-z]*/X11Forwarding no/' ${SSHD_CONFIG}
                    ${SSH_SVC} restart
            else
                    echo "already disabled"
            fi
            ;;
      *)
            echo "unrecognized option"
            exit 2
            ;;
    esac
    
    exit $?
    

    copy | embed

    0 comments - tagged in  posted by cgv on Apr 27, 2010 at 8:26 a.m. EDT
  • ssh-agent
    ssh-agent bash
    ssh-add
    

    copy | embed

    0 comments - tagged in  posted by dalord on Mar 19, 2010 at 11:10 a.m. EDT
  • SSH via TOR using SOCAT
    # start TOR
    tor
    
    # create tunnel
    socat TCP-LISTEN:<port> SOCKS4A:localhost:<host>:22,socksport=9050
    
    # login through local tunnel
    ssh <user>@localhost -p <port>
    

    copy | embed

    0 comments - tagged in  posted by lucastheis on Feb 06, 2010 at 7:46 p.m. EST
  • create ssh RSA id
    # Create an SSH id and public key pair (RSA) on your laptop/local machine
    mkdir ~/.ssh
    chmod 700 ~/.ssh
    ssh-keygen -q -f ~/.ssh/id_rsa -t rsa
    ## Enter passphrase (empty for no passphrase): …
    ## Enter same passphrase again: …
    
    # protect your SSH keys
    chmod go-w ~/
    chmod 700 ~/.ssh
    chmod go-rwx ~/.ssh/*
    
    # Send your public id to the server. 
    # @see http://snipt.net/jrguitar21/passwordless-rsa-ssh-1-liner/
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jan 29, 2010 at 10:26 a.m. EST
  • gits from server backup per ssh
    # run 'git-archive.sh' on server
    scp -r -P 1234 user@192.168.0.1:~/git/*.tar.gz /g/git
    

    copy | embed

    0 comments - tagged in  posted by dalord on Dec 24, 2009 at 5:54 a.m. EST
  • Play music on a remote linux (debian branch) computer via SSH
    #I used this technique to play music on a computer with a much better sound system from my laptop.
    
    #On the "music server"
    sudo apt-get install openssh-server mplayer
    
    #Once done, on the "controler" computer
    ssh <username>@<server_name_or_ip>
    cd /path/to/music/files
    #If you want to play only one song
    mplayer song.ext
    #If you want to play the whole directory
    mplayer *.ext
    #In case of multiple extentions (example with mp3, wma and ogg files
    mplayer *.mp3 *.wma *.ogg
    
    #You can control your music server from a windows comuputer with PuTTY
    

    copy | embed

    0 comments - tagged in  posted by Hregrin on Dec 05, 2009 at 6:59 a.m. EST
  • ssh disable timeout firewall
    http://madphilosopher.ca/2005/07/an-ssh-keep-alive-tip/
    
    It’s worth noting that many SSH timeouts come from firewalls and no amount of tinkering with timeout settings (other than on the firewall) will fix it. The only way in these cases is to simulate traffic (which is what the client’s keepalive settings should do, but don’t always in my experience).
    
    I find this works very well (although possibly it’s overkill being in perl):
    
    perl -e 'sleep 59 && print STDERR "\x00" while 1' &
    
    Run it as soon as you SSH in, and remember the pid so you can kill it before you leave. It squirts a null every 59 seconds. If you change the \x00 for a printable character you will see it appear on your terminal but it still won’t impact what you are doing.
    
    –
    # Adam Reed Says:
    May 6th, 2007 at 0303 UTC
    
    Bruce:
    
    You can automate this by putting the following in your .kshrc (or its equivalent for your shell in its rc file, or put it in .profile (or .login)):
    
    case $- in i*s*)
    perl -e 'sleep 59 && print STDERR "\x00" while 1' &
    trap "kill ${!}" 0
    ;;
    esac
    
    
    # =======================================================================================
    Remember that
    
    ServerAliveInterval
    
    is limited by
    
    ServerAliveCountMax
    
    and that ServerAliveCountMax is set to 3 by default!
    
    That is, if you set ServerAliveInterval to 60 and ServerAliveCountMax is left to default value (3), after the client has sent 3 keep alive packets it will disconnect. That makes 60 x 3 = 180 seconds.
    
    So if you want more time away, you set ServerAliveInterval to 60 and ServerAliveCountMax to the numer you want (for example: 100). The client will send one keep alive packet every 0 seconds for 100 times or, if you prefer, 100 keep alive packets, one every 60 seconds. :D
    
    You set this up in your $HOME/.ssh/config file.
    
    Most of these options are explained in man ssh_config.
    
    
    DiskStation> grep ClientAliveInterval /etc/ssh/sshd_config
    ClientAliveInterval 100
    

    copy | embed

    0 comments - tagged in  posted by rschu68 on Dec 02, 2009 at 8:13 a.m. EST
  • Continua descarga via SSH
    alias scpresume="rsync --partial --progress --rsh=ssh"
    scpresume archivo_origen usuario@hosts-destino:/path_destino
    

    copy | embed

    0 comments - tagged in  posted by boriscy on Nov 10, 2009 at 12:43 p.m. EST
  • run banshee from ssh session
    #!/bin/sh
    # run banshee from ssh session & auto play queque
    
    export DISPLAY=:0
    dbus-launch /usr/bin/banshee --play
    

    copy | embed

    0 comments - tagged in  posted by gin on Oct 26, 2009 at 3:21 p.m. EDT
  • Mailbox Plesk Diskusage
    cd /var/qmail/mailnames/; du -sh */*
    

    copy | embed

    0 comments - tagged in  posted by AvidDeville on Oct 20, 2009 at 1:48 p.m. EDT
  • Moving Magento to another server (the backup part)
    #!/bin/bash
    
    clear
    stty erase '^?'
    
    echo "-- File and DB Backup of Magento --"
    echo "The moving an installation of Magento as written on http://www.magentocommerce.com/wiki/groups/227/moving_magento_to_another_server"
    echo "Please note: It does not backup all the extensions and additional plugins. Back up all the files you added or changed manualy."
    echo
    
    check_dest_dir () {
        echo -n "Please enter the name of the directory the backup files will be stored in: "
        read dest_dir 
        
        if [ -d "$dest_dir" ]; then
        	  echo -n "Directory already exists. Use it for Backup [y] or specify another one [n]?"
        	  read use_dest_dir;
            if  [ "$use_dest_dir" = "y" ] ; then
               do_backup $dest_dir; 
               else  check_dest_dir;
            fi
        
        else 
            echo -n "Directory does not exist. Create it [c] or specify another one [n]?"
            read use_dest_dir
            if  [ "$use_dest_dir" = "c" ] ; then
               echo "Directory /"$dest_dir/" is to be created..."
               mkdir $dest_dir;
               do_backup $dest_dir;
            else check_dest_dir;
            fi
        fi
    }
    
    do_backup(){
        clear
        echo -n "Do the DATABASE dump? [y/n]"
        read do_database_dump
        if [ "$do_database_dump" = "y" ] ; then
          echo "Please enter the required information:"
          echo  -n  "- Database Host (usually localhost): "
          read  dbhost
          echo  -n  "- Database Name: "
          read  dbname
          echo  -n  "- Database User: "
          read  dbuser
          echo  -n  "- Database Password: "
          read  dbpass 
          echo "Creationg database DUMP. Please wait..."
          mysqldump -h DBHOST -u DBUSER -pDBPASS DBNAME > data.sql
          echo "Moving data.sql to your backup directory ($1)"
          mv data.sql $1/
        fi
         
       clear
       echo "TARing MEDIA..."
       tar -cvf media.tar media/*
       echo "Moving media.tar to your backup directory ($1)"
       mv media.tar $1/
      
       clear
       cd app/design/frontend/default/
       echo -n "About to TAR your Theme. What's the name of it?"
       read mytheme
       if [ -d "$mytheme" ]; then
          echo "Specified Theme Directory exists. TARing from app/ ..."
          tar -cvf app.tar $mytheme/
          echo "Moving app.tar to your backup directory ($1)"
          mv app.tar ../../../../$1/
          echo "TARing from skin/..."      
          cd ../../../../skin/frontend/default/
          tar -cvf skin.tar $mytheme/
          echo "Moving skin.tar to your backup directory ($1)"
          mv skin.tar ../../../$1/
       fi
       clear
       echo "Copying local.xml to your backup directory ($1)"
       cd ../../../
       cp app/etc/local.xml $1/
       echo "Copying .htaccess and php.ini to your backup directory ($1)"
       cp .htaccess php.ini $1/
       clear
       cd $1
       echo "Files in your backup:"
       ls     
    }
    
    check_dest_dir;
    

    copy | embed

    1 comment - tagged in  posted by lecomm on Oct 16, 2009 at 7:44 p.m. EDT
  • ssh port forwarding
    #This forwards all localhost:1234 connections to google.com:80 through gimli
    ssh -L 1234:google.com:80 gimli.cs.berkeley.edu
    

    copy | embed

    0 comments - tagged in  posted by njoubert on Oct 07, 2009 at 3:29 p.m. EDT
  • ssh rate limit iptables
    $/usr/sbin/iptables -I INPUT -p tcp --dport 22 -i eth1 -m state --state NEW -m recent --set
    
    $/usr/sbin/iptables -I INPUT -p tcp --dport 22 -i eth1 -m state --state NEW -m recent --update --seconds 1000 --hitcount 2 -j DROP
    

    copy | embed

    0 comments - tagged in  posted by tayhimself on Oct 05, 2009 at 11:17 a.m. EDT
  • how to create a git repo on a server under msysgit on windows
    cd /e/language/Project/src
    git init
    vim .gitignore      # *.pyc, *~
    git add .gitignore  # ...
    git commit -m "Initial commit"
    
    cd ../..            # /e/language
    git clone --bare Project/src project.git
    scp -r -P 1234 project.git user@192.168.0.1:~/git
    # delete 'Project' in Eclipse
    git clone ssh://user@192.168.0.1:1234/~/git/project.git project/src
    # recreate 'project' in Eclipse
    

    copy | embed

    0 comments - tagged in  posted by dalord on Sep 20, 2009 at 5:11 a.m. EDT
  • Deploying a CakePHP App on a Media Temple (dv) 3.5 Server using a Subdomain
    USE:
    	Deploy a CakePHP App to mysubdomain.example.com
    
    
    NOTE:
    	Looking to deploy on a regular domain like example.com?
    	See: http://snipt.net/chrisyour/deploying-a-cakephp-app-on-a-media-temple-dv-35-server/
    	
    	
    STEP 1: SET UP DOCUMENT ROOT VIA SSH
    
    	# TERMINAL: login to SSH as root (and enter your password)
    	ssh root@example.com
    
    	# TERMINAL: change directory to the conf folder (example.com)
    	cd /var/www/hosts/example.com/subdomains/mysubdomain/conf
    
    	# TERMINAL: use Vim (vi) to create your vhost.conf file
    	vi vhost.conf
    
    	# VIM: Press the 'i' key to begin inserting content
    
    	# VIM: Type in the document root into Vim
    	DocumentRoot "/var/www/vhosts/example.com/subdomains/mysubdomain/httpdocs/app/webroot"
    
    	# VIM: Press 'esc' key once you're finished inserting content
    
    	# VIM: Type ':wq' then press 'return' key to write to the vhost.conf file and quit Vim
    
    
    STEP 2: RECONFIGURE VHOST
    
    	# Terminal: 
    	/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=mysubdomain.example.com
    
    	# Terminal: Restart Apache
    	service httpd graceful
    
    
    STEP 3: MIGRATE YOUR DEVELOPMENT DATABASE TO YOUR PRODUCTION ENVIRONMENT
    
    	# Dump your local database into a .sql file on your computer
    
    	# Login to Plesk and use PHPMyAdmin to import your .sql
    
    
    STEP 4: UPLOAD YOUR CAKEPHP FILES
    
    	# Using FTP software (like Transmit), upload all the files in your CakePHP application to:
    	/var/www/vhosts/example.com/subdomains/mysubdomain/httpdocs
    
    	# Don't forget to upload your .htaccess files. Your FTP software may treat them as hidden files and skip them in the upload process. (If you're using Transmit, select View -> Show Invisible Files to make sure they are uploaded.)
    
    	# Don't forget to update your app/config/database.php file so your app will connect to the production database.
    
    
    STEP 5: FIRE IT UP
    
    	# Point your browser to http://mysubdomain.example.com
    

    copy | embed

    0 comments - tagged in  posted by chrisyour on Sep 18, 2009 at 8:26 p.m. EDT
  • Deploying a CakePHP App on a Media Temple (dv) 3.5 Server
    USE:
    	Deploy a CakePHP App to example.com
    
    
    NOTE:
    	Looking to deploy on a subdomain like mysubdomain.example.com?
    	See: http://snipt.net/chrisyour/deploying-a-cakephp-app-on-a-media-temple-dv-35-server-using-a-subdomain/
    	
    
    STEP 1: SET UP DOCUMENT ROOT VIA SSH
    
    	# TERMINAL: login to SSH as root (and enter your password)
    	ssh root@example.com
    
    	# TERMINAL: change directory to the conf folder (example.com)
    	cd /var/www/hosts/example.com/conf
    
    	# TERMINAL: use Vim (vi) to create your vhost.conf file
    	vi vhost.conf
    
    	# VIM: Press the 'i' key to begin inserting content
    
    	# VIM: Type in the document root into Vim
    	DocumentRoot "/var/www/vhosts/example.com/httpdocs/app/webroot"
    
    	# VIM: Press 'esc' key once you're finished inserting content
    
    	# VIM: Type ':wq' then press 'return' key to write to the vhost.conf file and quit Vim
    
    
    STEP 2: RECONFIGURE VHOST
    
    	# Terminal: 
    	/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=example.com
    
    	# Terminal: Restart Apache
    	service httpd graceful
    
    
    STEP 3: MIGRATE YOUR DEVELOPMENT DATABASE TO YOUR PRODUCTION ENVIRONMENT
    
    	# Dump your local database into a .sql file on your computer
    
    	# Login to Plesk and use PHPMyAdmin to import your .sql
    
    
    STEP 4: UPLOAD YOUR CAKEPHP FILES
    
    	# Using FTP software (like Transmit), upload all the files in your CakePHP application to:
    	/var/www/vhosts/example.com/httpdocs
    
    	# Don't forget to upload your .htaccess files. Your FTP software may treat them as hidden files and skip them in the upload process. (If you're using Transmit, select View -> Show Invisible Files to make sure they are uploaded.)
    
    	# Don't forget to update your app/config/database.php file so your app will connect to the production database.
    
    
    STEP 5: FIRE IT UP
    
    	# Point your browser to http://example.com
    

    copy | embed

    0 comments - tagged in  posted by chrisyour on Sep 18, 2009 at 8:18 p.m. EDT
  • ssh login auf port 1234 als user auf rechner 192.168.0.1
    ssh -p 1234 user@192.168.0.1
    

    copy | embed

    0 comments - tagged in  posted by dalord on Sep 10, 2009 at 2:58 a.m. EDT
  • Mount SSH volume on Mac with sshfs
    # With sshfs installed:
    
    MOUNTPOINT=/Volumes/mountdir
    REMOTE=user@hostname:/home/dir
    OPTIONS=-oping_diskarb,volname=mountdir
    TESTHOST=hostname
    #test if sshfs already mounted
    if ! [ -e $MOUNTPOINT ]
    then
            #test if connected to internet
            if ! [ -z "`ping -c 1 $TESTHOST 2>/dev/null | grep "time="`" ]
            then
                    mkdir $MOUNTPOINT
                    sshfs $REMOTE $MOUNTPOINT $OPTIONS
                    echo "$REMOTE mounted on $MOUNTPOINT"
            else
                    echo "Network down, unable to mount $REMOTE"
            fi
    fi
    

    copy | embed

    0 comments - tagged in  posted by Fotinakis on Aug 18, 2009 at 6:59 p.m. EDT
Sign up to create your own snipts, or login.