Commands matching ssh (499)

  • (Useful when firewalls prevent you from using NTP.)


    5
    sudo date -s "$(ssh user@server.com "date -u")"
    rpavlick · 2010-03-31 11:59:27 4
  • Quick shortcut if you know the hostname and want to save yourself one step for looking up the IP address separately.


    5
    ssh-keygen -R `host hostname | cut -d " " -f 4`
    flart · 2009-09-23 14:58:28 8
  • You can use this to directly dump from machine A (with dvd drive) to machine B (without dvd drive) . I used this to copy dvd using my friend's machine to my netbook. Above command is to be issued on machine B. Advantages : 1) No wasting time dumping first to machine A and then copying to Machine B. 2) You dont need to use space on Machine A. In fact, this will work even when Machine A doesnt have enough hdd space to dump the DVD. Use -C ssh option on slow networks (enables compression). you can replace "dd if=/dev/dvd" with any ripping command as long as it spews the iso to stdout.


    5
    ssh user@machine_A dd if=/dev/dvd0 > dvddump.iso
    kamathln · 2009-09-11 18:08:36 12
  • I have a small embedded linux device that I wanted to use for sniffing my external network, but I didn't want to recompile/cross-compile snort for the embedded platform. So I used tcpdump over ssh to pass all the traffic as pcap data to a "normal" Linux system that then takes the pcap data and passes it to snort for processing.


    5
    ssh root@pyramid \ "tcpdump -nn -i eth1 -w -" | snort -c /etc/snort/snort.conf -r -
    omish_man · 2009-08-24 14:04:06 5
  • Same as original just no $ at start


    5
    ssh-copy-id user@host
    matthewbauer · 2009-08-07 16:36:19 20
  • If you have lots of remote hosts sitting "behind" an ssh proxy host, then there is a special-case use of "rsynch" that allows one to easily copy directories and files across the ssh proxy host, without having to do two explicit copies: the '-e' option allows for a replacement "rsh" command. We use this option to specify an "ssh" tunnel command, with the '-A' option that causes authentication agent requests to be forwarded back to the local host. If you have ssh set up correctly, the above command can be done without any passwords being entered.


    5
    rsync -avz -e 'ssh -A sshproxy ssh' srcdir remhost:dest/path/
    totoro · 2009-03-25 21:29:07 11
  • I recently found myself with a filesystem I couldn't write to and a bunch of files I had to get the hell out of dodge, preferably not one at a time. This command makes it possible to pack a bunch of files into a single archive and write it to a remote server.


    5
    tar -czf - * | ssh example.com "cat > files.tar.gz"
    migurski · 2009-03-24 17:02:02 8
  • Enter your ssh public key in the remote end for future key-based authentication. Just type your password one last time. The next time you should be able to login with the public key. If you don't have a key, generate one with ssh-keygen. Requires Bourne-compatible shell in the remote end.


    5
    cat .ssh/id_dsa.pub | ssh elsewhere "[ -d .ssh ] || mkdir .ssh ; cat >> .ssh/authorized_keys"
    jsiren · 2009-02-18 22:13:04 7
  • This option makes a copy of your current db and via ssh it transfer to the server you specify and upload the database to the specific User & Password you specify (Note the db User & Pass, can be different from the one you use in the other server) If you are going to use "localhost" as your main db remove (-h) and youst add "localhost"


    5
    mysqldump -uUserName -pPassword tudb | ssh root@rootsvr.com "mysql -uUserName -pPassword -h mysql.rootsvr.com YourDBName"
    elecboy · 2009-02-17 22:36:06 10
  • Simply change your web browser's proxy settings to point to a SOCKS proxy at port 8888 and you're good to go.


    5
    ssh -D 8888 user@site.com
    wesrog · 2009-02-17 15:34:27 7
  • Should run on any system with ssh installed.


    5
    cat ~/.ssh/*.pub | ssh user@remote-system 'umask 077; cat >>.ssh/authorized_keys'
    DASKAjA · 2009-02-16 11:29:12 99
  • ...can do similar w/ tar, dd, xfsdump, e2fsdump, etc.


    5
    dump 0f - / | bzip -c9 | ssh user@host "cat > /home/user/root.dump.bz2"
    wwest4 · 2009-02-05 17:22:32 15
  • 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.


    4
    if [ "${SSH_CLIENT%% *}" == "ipaddr" ]; then command; fi
    snipertyler · 2015-01-13 22:09:38 10
  • Mirror a remote directory using some tricks to maximize network speed. lftp:: coolest file transfer tool ever -u: username and password (pwd is merely a placeholder if you have ~/.ssh/id_rsa) -e: execute internal lftp commands set sftp:connect-program: use some specific command instead of plain ssh ssh:: -a -x -T: disable useless things -c arcfour: use the most efficient cipher specification -o Compression=no: disable compression to save CPU mirror: copy remote dir subtree to local dir -v: be verbose (cool progress bar and speed meter, one for each file in parallel) -c: continue interrupted file transfers if possible --loop: repeat mirror until no differences found --use-pget-n=3: transfer each file with 3 independent parallel TCP connections -P 2: transfer 2 files in parallel (totalling 6 TCP connections) sftp://remotehost:22: use sftp protocol on port 22 (you can give any other port if appropriate) You can play with values for --use-pget-n and/or -P to achieve maximum speed depending on the particular network. If the files are compressible removing "-o Compression=n" can be beneficial. Better create an alias for the command. Show Sample Output


    4
    lftp -u user,pwd -e "set sftp:connect-program 'ssh -a -x -T -c arcfour -o Compression=no'; mirror -v -c --loop --use-pget-n=3 -P 2 /remote/dir/ /local/dir/; quit" sftp://remotehost:22
    colemar · 2014-10-17 00:29:34 10
  • You need to install "sshpass" for this to work. apt-get install sshpass


    4
    sshpass -p "YOUR_PASSWORD" ssh -o StrictHostKeyChecking=no YOUR_USERNAME@SOME_SITE.COM
    o0110o · 2013-05-24 14:33:38 12
  • 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.


    4
    cat ~/.ssh/id_rsa.pub | ssh <REMOTE> "(cat > tmp.pubkey ; mkdir -p .ssh ; touch .ssh/authorized_keys ; sed -i.bak -e '/$(awk '{print $NF}' ~/.ssh/id_rsa.pub)/d' .ssh/authorized_keys; cat tmp.pubkey >> .ssh/authorized_keys; rm tmp.pubkey)"
    tamouse · 2011-09-30 07:39:24 18
  • Requires you to have password free login to remote host ;) Requires xclip and notify-send (If you want to put into clipboard and be notified when action is completed). DATE=$(date +%Y-%m-%d_%H-%M-%S)-$(($(date +%N)/10000000)); HOST="ssh host of your choice"; DEST="destination folder without trailing slash"; URL="URL for file if uploaded to web enabled dir ie. import -window root png:- | ssh $HOST "cat > $DEST/screenshot_$DATE.png"; echo $URL | xclip; notify-send -u low "Screenshot Taken" "Entire screen.\nCopied to clipboard" Show Sample Output


    4
    DATE=$(date +%Y-%m-%d_%H-%M-%S)-$(($(date +%N)/10000000)); HOST=ssh_host; DEST=file_dest; URL=url/screenshot_$DATE.png; import -window root png:- | ssh $HOST "cat > $DEST/screenshot_$DATE.png"; echo $URL | xclip; notify-send -u low "Title" "Message"
    DELETETHISACCOUN · 2011-08-13 00:40:36 5
  • Record off the microphone on a remote computer and listen to it live through your speakers locally. Show Sample Output


    4
    ssh USER@REMOTESYSTEM arecord - | aplay -
    mu_mind · 2011-01-31 16:49:45 100
  • Create a persistent remote Proxy server through an SSH channel. Show Sample Output


    4
    ssh -fND localhost:PORT USER@SSH_ENABLED_SERVER
    2dvisio · 2010-12-01 14:42:13 5
  • - 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


    4
    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 4
  • 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


    4
    alias sshv='ssh -vvv -o LogLevel=DEBUG3'
    AskApache · 2010-10-30 11:23:52 4

  • 4
    ssh user@remote 'cat >> ~/.ssh/authorized_keys2' < ~/.ssh/id_rsa.pub
    yababay · 2010-08-27 07:47:05 5
  • Useful to create an alias that sends you right in the directory you want : alias server-etc="ssh -t server 'cd /etc && $SHELL'"


    4
    ssh -t server 'cd /etc && $SHELL'
    dooblem · 2010-04-02 19:34:09 6
  • When you start screen as `ssh-agent screen`, agent will die after detatch. If you don't want to take care about files when stored agent's pid/socket/etc, you have to use this command.


    4
    eval `ssh-agent`; screen
    mechmind · 2010-03-07 14:58:54 3
  • This creates a persistent ssh -i /path/to/key -ND local-IP:PORT User@Server connection. You may have to install autossh. -f puts in daemon mode. if you are having trouble, try it without -f.


    4
    autossh -f -i /path/to/key -ND local-IP:PORT User@Server
    fotoflo · 2009-12-31 06:10:03 5
  • ‹ First  < 4 5 6 7 8 >  Last ›

What's this?

commandlinefu.com 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

recursively change file name from uppercase to lowercase (or viceversa)
easier way to recursively change files to lowercase using rename instead

Record live sound in Vorbis (eg for bootlegs or to take audio notes)
This will record the capture channel of your soundcard, directly encoded in Ogg Vorbis, in stereo at quality 5 (I'm using this to record live jam sessions from my line input). You can choose which device to capture (eg. line input, microphone or PCM output) with $ alsamixer -V capture You can do the same thing and live encode in MP3 or FLAC if you wish, just check FLAC and LAME man pages.

Url Encode

Deleting / Ignoring lines from the top of a file
Output lines starting at line 2.

Print the IP address and the Mac address in the same line
Print the IP address and the Mac address in the same line

stop man page content from disappearing on exit
stop man page content from disappearing on exit echo "export LESS='FiX'" >> ~/.bashrc man bash 'q'uit out of man page content will stay on screen

creating you're logging function for your script
You could also pipe to logger.

Find usb device
I often use it to find recently added ou removed device, or using find in /dev, or anything similar. Just run the command, plug the device, and wait to see him and only him

backup with mysqldump a really big mysql database to a remote machine over ssh
backup big mysql db to remote machine over ssh. "--skip-opt" option is needed when you can?t allocate full database in ram.

Remove annoying files from recently extracted zip archive
Inspired by http://www.commandlinefu.com/commands/view/2573/remove-all-files-previously-extracted-from-a-tar.gz-file. .... yet for zip files


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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: