Commands tagged ssh (190)

  • the command is obvious, I know, but maybe not everyone knows that using the parameter "-l" you can limit the use of bandwidth command scp. In this example fetch all files from the directory zutaniddu and I copy them locally using only 10 Kbs


    11
    scp -l10 pippo@serverciccio:/home/zutaniddu/* .
    0disse0 · 2010-02-19 16:44:24 13
  • Will return the SSH server key information for each host you have in your ~/.ssh/known_hosts file, including key size, key fingerprint, key IP address or domain name, and key type. Show Sample Output


    11
    ssh-keygen -l -f ~/.ssh/known_hosts
    atoponce · 2010-12-05 04:03:07 6
  • This is useful for example if you are on ssh in a server and the server goes down without letting you out. This is part of a larget sets of escape sequences provided by ssh. You can find them with ~? Here's the list: ~. - terminate connection (and any multiplexed sessions) ~B - send a BREAK to the remote system ~C - open a command line ~R - request rekey ~V/v - decrease/increase verbosity (LogLevel) ~^Z - suspend ssh ~# - list forwarded connections ~& - background ssh (when waiting for connections to terminate) ~? - this message ~~ - send the escape character by typing it twice (Note that escapes are only recognized immediately after newline.) Show Sample Output


    11
    <Return>~.
    carlesso · 2013-06-26 13:34:58 12
  • This command will bypass checking the host key of the target server against the local known_hosts file. When you SSH to a server whose host key does not match the one stored in your local machine's known_hosts file, you'll get a error like " WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!" that indicates a key mismatch. If you know the key has legitimately changed (like the server was reinstalled), a permanent solution is to remove the stored key for that server in known_hosts. However, there are some occasions where you may not want to make the permanent change. For example, you've done some port-forwarding trickery with ssh -R or ssh -L, and are doing ssh user@localhost to connect over the port-forwarding to some other machine (not actually your localhost). Since this is usually temporary, you probably don't want to change the known_hosts file. This command is useful for those situations. Credit: Command found at http://linuxcommando.blogspot.com/2008/10/how-to-disable-ssh-host-key-checking.html. Further discussion of how it works is there also. Note this is a bit different than command #5307 - with that one you will still be prompted to store the unrecognized key, whereas this one won't prompt you for the key at all.


    10
    ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no username@host
    dmmst19 · 2012-04-20 01:54:04 7
  • This command checks for the number of times when someone has tried to login to your server and failed. If there are a lot, then that user is being targeted on your system and you might want to make sure that user either has remote logins disabled, or has a strong password, or both. If your output has an "invalid" line, it is a summary of all logins from users that don't exist on your system. Show Sample Output


    9
    zgrep "Failed password" /var/log/auth.log* | awk '{print $9}' | sort | uniq -c | sort -nr | less
    dbart · 2009-03-03 13:45:56 11
  • you may create an alias also, which I did ;-) alias sshu="ssh -o UserKnownHostsFile=/dev/null "


    9
    ssh -o UserKnownHostsFile=/dev/null root@192.168.1.1
    oernii2 · 2010-04-08 14:55:58 5

  • 9
    mussh -h host1 host2 host3 -c uptime
    george_007 · 2010-08-29 03:04:51 5
  • Booting the VM headless via VBoxHeadless requires knowledge of the VM's network in order to connect. Using VBoxManage in this way and you can SSH to the VM without first looking up the current IP, which changes depending on how you have your VM configured. Show Sample Output


    9
    ssh vm-user@`VBoxManage guestproperty get "vm-name" "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print $2 }'`
    lucasrangit · 2011-05-04 18:01:36 6

  • 9
    ssh -J user@reachable_host user@unreacheable_host
    renich · 2019-08-14 17:29:45 69
  • Here how to recover the remote backup over ssh Show Sample Output


    8
    ssh user@host "cat /path/to/backup/backupfile.tar.bz2" |tar jpxf -
    mack · 2010-03-24 01:35:28 7
  • It grabs all the database names granted for the $MYSQLUSER and gzip them to a remote host via SSH.


    7
    for I in $(mysql -e 'show databases' -u root --password=root -s --skip-column-names); do mysqldump -u root --password=root $I | gzip -c | ssh user@server.com "cat > /remote/$I.sql.gz"; done
    juliend2 · 2010-03-07 15:03:12 7
  • This will allow you to convert an audio file to wav format, and send it via ssh to a player on the other computer, which will open and play it there. Of course, substitute your information for the sound file and remote address You do not have to use paplay on the remote end, as it is a PulseAudio thing. If the remote end uses ALSA, you should use aplay instead. If it uses OSS, you should berate them about having a lousy sound system. Also, you're not limited to transmitting encoded as wav either, it's just that AFAIK, most systems don't come with mp3 codecs, but will play wav files fine. If you know SoX is installed on the remote end and has mp3 codecs, you can use the following instead: cat Klaxon.mp3 |ssh thelab@company.com play -t mp3 - this will transmit as mp3. Again, use your specific information. if you're not playing mp3s, use another type with the -t option


    7
    sox Klaxon.mp3 -t wav - |ssh thelab@company.com paplay
    camocrazed · 2010-07-29 23:23:39 42
  • Run local scripts on remote server. "-T Disable pseudo-tty allocation"


    7
    ssh -T user@server < script.sh
    dlebauer · 2011-01-10 20:09:55 7
  • The command uses ssh(1) to get to a remote host, uses tar(1) to archive a remote directory, prints the result to STDOUT, which is piped to gzip(1) to compress to a local file. In other words, we are archiving and compressing a remote directory to our local box.


    7
    ssh user@host "tar -cf - /path/to/dir" | gzip > dir.tar.gz
    atoponce · 2011-12-14 15:54:57 11
  • Securely stream a file from a remote server (and save it locally). Useful if you're impatient and want to watch a movie immediately and download it at the same time without using extra bandwidth. This is an extension of snipertyler's idea. Note: This command uses an encrypted connection, unlike the original. Show Sample Output


    7
    ssh USER@HOST cat REMOTE_FILE.mp4 | tee LOCAL_FILE.mp4 | mplayer -
    flatcap · 2013-11-28 11:25:26 9
  • Optionally, you can create a new function to do this with a custom command. Edit $HOME/.bashrc and add: myssh () { ssh $1 | tee sshlog ; } Save it. At command prompt: myssh user@server Show Sample Output


    6
    ssh user@server | tee logfilename
    bassu · 2009-04-17 19:17:02 9
  • Uses ssh as tunnel tunnel for an other connection. -f runs ssh in the background -N tell that there is no command to run -L deals with the forwarding aspect where the first number is the local port number, the second is parameter is the name of the server to forward to and the third parameter is the port number on that server. The last part of the command is the usual ssh form consisting of the user name and remote server name


    6
    ssf -f -N -L 4321:home.network.com:25 user@home.network.com
    dcabanis · 2009-06-05 23:12:02 7
  • ssh_config is the system-wide configuration file for ssh. For per-user configuration, which allows for different settings for each host: echo 'ServerAliveInterval 60' >> ~/.ssh/ssh_config On OSX: echo 'ServerAliveInterval 60' >> ~/.ssh/config or echo 'ServerAliveInterval 60' >> ~/etc/ssh_config


    6
    echo 'ServerAliveInterval 60' >> /etc/ssh/ssh_config
    rpavlick · 2010-03-31 09:22:54 7
  • The above command will send 4GB of data from one host to the next over the network, without consuming any unnecessary disk on either the client nor the host. This is a quick and dirty way to benchmark network speed without wasting any time or disk space. Of course, change the byte size and count as necessary. This command also doesn't rely on any extra 3rd party utilities, as dd, ssh, cat, /dev/zero and /dev/null are installed on all major Unix-like operating systems. Show Sample Output


    6
    dd if=/dev/zero bs=4096 count=1048576 | ssh user@host.tld 'cat > /dev/null'
    atoponce · 2010-06-08 18:49:51 10
  • Require: - tsocks (deb pkg) - A working SOCKS proxy. It's easy with ssh: $ ssh -N -D localhost:1080 your.home.pc -p 443 - tsocks configuration in your /etc/tsocks.conf (for the previous): server = 127.0.0.1 server_port = 1080


    6
    tsocks <program>
    prayer · 2010-07-11 14:16:06 3
  • This one doesn't need to convert to wav.


    6
    ssh [user]@[address] "mpg321 -" < [file].mp3
    leovailati · 2010-07-30 00:23:13 3
  • 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
  • this command from the source server and this follow in the destination server: ssh user@localhost -p 8888


    5
    ssh -f -N -R 8888:localhost:22 user@somedomain.org
    0disse0 · 2012-02-08 20:24:38 16
  • Use as: $ s host1 Will ssh to remote host upon first invocation. Then use C-a d to detatch. Running "s host1" again will resume the shell session on the remote host. Only useful in LAN environment. You'd want to start the screen on the remote host over a WAN. Adapted from Hack 34 in Linux Server Hacks 2nd Addition.


    5
    s() { screen -d -RR -m -S "$1" -t "$USER"@"$1" ssh "$1"; }
    salamando · 2012-09-07 23:02:52 5
  • While `sshfs $REMOTE_HOST:$REMOTE_PATH $LOCAL_PATH` "pulls" a directory from the remote server to the local host, the above command does the reverse and "pushes" a directory from the local host to the remote server. This makes use of the "slave" option of sshfs which instructs it to communicate over plain stdin/stdout and the `dpipe` tool from vde2 to connect the sftp-server stdout to the sshfs stdin and vice-versa.


    5
    dpipe /usr/lib/openssh/sftp-server = ssh $REMOTE_HOST sshfs whatever:$LOCAL_PATH $REMOTE_PATH -o slave
    em · 2014-03-25 17:40:34 7
  •  < 1 2 3 4 >  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

Replicate a directory structure dropping the files

find out how many days since given date
You can also do this for seconds, minutes, hours, etc... Can't use dates before the epoch, though.

Count number of files in subdirectories
For each directory from the current one, list the counts of files in each of these directories. Change the -maxdepth to drill down further through directories.

Adequately order the page numbers to print a booklet
Useful if you don't have at hand the ability to automatically create a booklet, but still want to. F is the number of pages to print. It *must* be a multiple of 4; append extra blank pages if needed. In evince, these are the steps to print it, adapted from https://help.gnome.org/users/evince/stable/duplex-npage.html.en : 1) Click File ▸ Print. 2) Choose the General tab. Under Range, choose Pages. Type the numbers of the pages in this order (this is what this one-liner does for you): n, 1, 2, n-1, n-2, 3, 4, n-3, n-4, 5, 6, n-5, n-6, 7, 8, n-7, n-8, 9, 10, n-9, n-10, 11, 12, n-11... ...until you have typed n-number of pages. 3) Choose the Page Setup tab. - Assuming a duplex printer: Under Layout, in the Two-side menu, select Short Edge (Flip). - If you can only print on one side, you have to print twice, one for the odd pages and one for the even pages. In the Pages per side option, select 2. In the Page ordering menu, select Left to right. 4) Click Print.

Sort files by date
Show you the list of files of current directory sorted by date youngest to oldest, remove the 'r' if you want it in the otherway.

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

reverse-i-search: Search through your command line history
"What it actually shows is going to be dependent on the commands you've previously entered. When you do this, bash looks for the last command that you entered that contains the substring "ls", in my case that was "lsof ...". If the command that bash finds is what you're looking for, just hit Enter to execute it. You can also edit the command to suit your current needs before executing it (use the left and right arrow keys to move through it). If you're looking for a different command, hit Ctrl+R again to find a matching command further back in the command history. You can also continue to type a longer substring to refine the search, since searching is incremental. Note that the substring you enter is searched for throughout the command, not just at the beginning of the command." - http://www.linuxjournal.com/content/using-bash-history-more-efficiently

Get the list of local files that changed since their last upload in an S3 bucket
Can be useful to granulary flush files in a CDN after they've been changed in the S3 bucket.

print DateTimeOriginal from EXIF data for all files in folder
see output from `identify -verbose` for other keywords to filter for (e.g. date:create, exif:DateTime, EXIF:ExifOffset).

Change every instance of OLD to NEW in file FILE
Very quick way to change a word in a file. I use it all the time to change variable names in my PHP scripts (sed -i 's/$oldvar/$newvar/g' index.php)


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: