Commands tagged ssh (188)

  • Bash process substitution which curls the website '' and executes the shell script embedded in the page. This is obviously not the most secure way to run something like this, and we will scold you if you try. The smarter way would be: Download locally over SSL > curl >> Verify integrty with GPG (If available) > gpg --recv-keys 0xD2C4C74D8FAA96F5 > gpg --verify Inspect source code > less Run > chmod +x > ./

    sh <(curl
    lrvick · 2015-03-15 21:02:01 2
  • Set Remote Server Date using Local Server Time (push) Show Sample Output

    ssh user@server sudo date -s @`( date -u +"%s" )`
    daryltucker · 2015-03-26 20:25:23 2
  • I find it ugly & sexy at the same time isn't it ?

    [[ $(COLUMNS=200 ps faux | awk '/grep/ {next} /ssh -N -R 4444/ {i++} END {print i}') ]] || nohup ssh -N -R 4444:localhost:22 user@relay &
    j0rn · 2009-03-31 09:39:59 3
  • This starts a very basic X session, with just a simple xterm. You can use this xterm to launch your preferred distant session. ssh -X john@otherbox gnome-session Try also startkde or fluxbox or xfce4-session. To switch between your two X servers, use CTRL+ALT+F7 and CTRL+ALT+F8.

    xinit -- :1
    flux · 2009-07-31 23:42:28 1
  • middlehost allows ssh access from where you are but not securehost. Use nice ssh piping to simulate scp through A => B => C setting up the shell function if left as an exercise for the reader. ;-) Agent forwarding should avoid password typing.

    cat nicescript |ssh middlehost "cat | ssh -a root@securehost 'cat > nicescript'"
    syladmin · 2009-08-25 08:11:12 1
  • dsh - Distributed shell, or dancer?s shell ;-) you can put your servers into /etc/dsh/machines.list than you don't have to serperate them by commata or group them in different files and only run commands for this groups dsh -M -c -a -- "apt-get update" Show Sample Output

    dsh -M -c -f servers -- "command HERE"
    foob4r · 2009-08-31 12:08:38 0
  • Get your server's fingerprints to give to users to verify when they ssh in. Publickey locations may vary by distro. Fingerprints should be provided out-of-band. Show Sample Output

    ssh-keygen -l -f /etc/ssh/ && ssh-keygen -l -f /etc/ssh/
    Mikelifeguard · 2009-10-26 17:52:41 0

  • 4
    startx -- /usr/X11R6/bin/Xnest :5 -geometry 800x600
    ivanatora · 2010-02-26 11:02:27 2
  • Useful to create an alias that sends you right in the directory you want : alias server-etc="ssh -t server 'cd /etc && $SHELL'"

    ssh -t server 'cd /etc && $SHELL'
    dooblem · 2010-04-02 19:34:09 0
  • When debugging an ssh connection either to optimize your settings ie compression, ciphers, or more commonly for debugging an issue connecting, this alias comes in real handy as it's not easy to remember the '-o LogLevel=DEBUG3' argument, which adds a boost of debugging info not available with -vvv alone. Especially useful are the FD info, and the setup negotiation to create a cleaner, faster connection. Show Sample Output

    alias sshv='ssh -vvv -o LogLevel=DEBUG3'
    AskApache · 2010-10-30 11:23:52 0
  • - port 8080 on localhost will be a SOCKSv5 proxy - at localhost:localport1 you will be connected to the external source server1:remoteport1 and at bind_address2:localport2 to server2:remoteport2 - you will be using only IPv4 and arcfour/blowfish-cbc, in order to speed up the tunnel - if you lose the connection, autossh will resume it at soon as possible - the tunnel is here a background process, wiithout any terminal window open

    autossh -M 0 -p 22 -C4c arcfour,blowfish-cbc -NfD 8080 -2 -L localport1:server1:remoteport1 -L bind_address2:localport2:server2:remoteport2 user@sshserver
    dddddsadasdasd · 2010-11-13 23:49:09 0
  • This one is a bit more robust -- the remote machine may not have an .ssh directory, and it may not have an authorized_keys file, but if it does already, and you want to replace your ssh public key for some reason, this will work in that case as well, without duplicating the entry.

    cat ~/.ssh/ | ssh <REMOTE> "(cat > tmp.pubkey ; mkdir -p .ssh ; touch .ssh/authorized_keys ; sed -i.bak -e '/$(awk '{print $NF}' ~/.ssh/' .ssh/authorized_keys; cat tmp.pubkey >> .ssh/authorized_keys; rm tmp.pubkey)"
    tamouse · 2011-09-30 07:39:24 2
  • You need to install "sshpass" for this to work. apt-get install sshpass

    sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM
    o0110o · 2013-05-24 14:33:38 3
  • Place in ~/.bashrc If you login to a ssh server from different ips, sometimes you want to do something specific for each. e.g., quickly go into screen -x session from a phone, but not your desktop.

    if [ "${SSH_CLIENT%% *}" == "ipaddr" ]; then command; fi
    snipertyler · 2015-01-13 22:09:38 2
  • The ssh command alone will execute the sudo command remotely, but the password will be visible in the terminal as you type it. The two stty commands disable the terminal from echoing the password back to you, which makes the remote sudo act as it does locally.

    stty -echo; ssh -t HOSTNAME "sudo some_command"; stty echo
    jmcantrell · 2009-03-04 19:44:36 3
  • I used this to confirm an upgrade to an SSH daemon was successful Show Sample Output

    ssh -vN hostname 2>&1 | grep "remote software version"
    sud0er · 2009-03-31 18:28:41 1
  • Redirects the contents of your clipboard through a pipe, to a remote machine via SSH.

    pbpaste | ssh user@hostname 'cat > ~/my_new_file.txt'
    mikedamage · 2009-07-14 16:32:03 0

  • 3
    mkfifo /tmp/fifo; ssh-keygen; ssh-copyid root@remotehostaddress; sudo ssh root@remotehost "tshark -i eth1 -f 'not tcp port 22' -w -" > /tmp/fifo &; sudo wireshark -k -i /tmp/fifo;
    Code_Bleu · 2010-01-05 14:40:06 0
  • You set the file/dirname transfer variable, in the end point you set the path destination, this command uses pipe view to show progress, compress the file outut and takes account to change the ssh cipher. Support dirnames with spaces. Merged ideas and comments by and Show Sample Output

    file='path to file'; tar -cf - "$file" | pv -s $(du -sb "$file" | awk '{print $1}') | gzip -c | ssh -c blowfish user@host tar -zxf - -C /opt/games
    starchox · 2010-01-19 16:02:45 2
  • You may go to Internet by means of your home ssh server. You must configure your local proxy to send traffic through the proxy. Many programs allows that: firefox, pidgin, skype, gnome, etc. Your home ssh server must listen in any of the ports permitted by your enterprise firewall. That usually includes 80 and 443. Show Sample Output

    autossh -N -D localhost:1080 -p 443
    prayer · 2010-05-22 19:52:30 0
  • Do the same as pssh, just in shell syntax. Put your hosts in hostlist, one per line. Command outputs are gathered in output and error directories.

    xargs -n1 -P100 -I{} sh -c 'ssh {} uptime >output/{} 2>error/{}' <hostlist
    dooblem · 2010-08-20 11:03:11 0
  • This version transfers gzipped data which is unzipped as it arrives at the remote host.

    ssh user@host 'gunzip - > file' < file.gz
    putnamhill · 2010-09-20 14:04:47 0
  • If you need to xdebug a remote php application, which is behind a firewall, and you have an ssh daemon running on that machine. you can redirect port 9000 on that machine over to your local machine from which you run your xdebug client (I am using phpStorm) So, run this command on your local machine and start your local xdebug client, to start debugging. more info:

    ssh -R 9000:localhost:9000
    nadavkav · 2011-05-28 09:39:16 1
  • commandline for mac os x

    ssh sudo tcpdump -i eth0 -w - 'port 80'| /Applications/ -k -i -
    bkendinibilir · 2012-01-23 18:16:22 0
  • Example: remote install an application(wine). sshpass -p 'mypssword' ssh -t mysshloginname@ "echo 'mypassword' | sudo -S apt-get install wine" Tested on Ubuntu.

    sshpass -p 'sshpssword' ssh -t <sshuser>@<remotehost> "echo <sudopassword> | sudo -S <command>"
    dynaguy · 2012-09-13 20:27:13 5
  •  < 1 2 3 4 5 >  Last ›

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

Search some text from all files inside a directory

Convert PDF to JPG
(relies on 'imagemagick') This command will convert all .pdf files in a directory into a 800px (wide or height, whichever is smaller) image (with the aspect ratio kept) .jpg. If the file is named 'example1.pdf' it will be named 'example1.jpg' when it is complete. This is a VERY worthwhile command! People pay hundreds of dollars for this in the Windows world. My .jpg files average between 150kB to 300kB, but your's may differ.

list process ids for given program

Find name of package which installed a given shell command
Some command names are very different from the name of the package that installed them. Sometimes, you may want to find out the name of the package that provided a command on a system, so that you can install it on another system.

find and delete files smaller than specific size

Length of longest line of code
Here's an awk version.

Force an fsck on reboot
Force an fsck on reboot. Useful on a system where / has mounted read-only because of file system issues.

Migrate existing Ext3 filesystems to Ext4
Before doing this, back-up all data on any ext3 partitions that are to be converted to ext4. After running previous command you MUST run fsck, is needed to return the filesystem to a consistent state. $ fsck -pDf /dev/yourpartition Edit /etc/fstab and change the 'type' from ext3 to ext4 for any partitions that are converted to ext4.

Export MySQL query as .csv file
This command converts a MySQL query directly into a .csv (Comma Seperated Value)-file.

tee to a file descriptor
the tee command does fine with file names, but not so much with file descriptors, such as &2 (stderr). This uses process redirection to tee to the specified descriptor. In the sample output, it's being used to tee to stderr, which is connected with the terminal, and to wc -l, which is also outputting to the terminal. The result is the output of bash --version followed by the linecount

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: