Commands tagged ssh (186)

  • 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
  • - 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
  • This command uses the reachable_host as a proxy; redirecting your request to the unreachable_host. The main advantage is that you need only one ssh key. You copy the public part to both servers and you can access the unreachable_host without a problem. Also, you can put this on ~/.ssh/config to access the unreachable_host directly: # config unreachable_host ProxyCommand ssh user@reachable_host -W %h:%p and, then, just ssh user@unreachable_host.

    ssh -o "ProxyCommand ssh user@reachable_host -W %h:%p" user@unreacheable_host
    renich · 2015-06-26 06:23:14 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 0
  • 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
  • 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
  • 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
  • A wrapper around ssh to automatically provide logging and session handling. This function runs ssh, which runs screen, which runs script. . The logs and the screen session are stored on the server. This means you can leave a session running and re-attach to it later, or from another machine. . . Requirements: * Log sessions on a remote server * Transparent - nothing extra to type * No installation - nothing to copy to the server beforehand . Features: * Function wrapper delegating to ssh - so nothing to remember - uses .ssh/config as expected - passes your command line option to ssh * Self-contained: no scripts to install on the server * Uses screen(1), so is: - detachable - re-attachable - shareable * Records session using script(1) * Configurable log file location, which may contain variables or whitespace L="$HOME" # local variable L="\$HOME" # server variable L="some space" . Limitations: * Log dir/file may not contain '~' (which would require eval on the server) . . The sessions are named by the local user connecting to the server. Therefore if you detach and re-run the same command you will reconnect to your original session. If you want to connect/share another's session simply run: USER=bob ssh root@server . The command above is stripped down to an absolute minimum. A fully expanded and annotated version is available as a Gist (git pastebin): . If you want to add timing info to script, change the command to: ssh(){ L="\$HOME/logs/$(date +%F_%H:%M)-$USER";/usr/bin/ssh -t "$@" "mkdir -p \"${L%/*}\";screen -xRRS $USER script --timing=\"$L-timing\" -f \"$L\"";} Show Sample Output

    ssh(){ L="\$HOME/logs/$(date +%F_%H:%M)-$USER";/usr/bin/ssh -t "$@" "mkdir -p \"${L%/*}\";screen -xRRS $USER script -f \"$L\"";}
    flatcap · 2015-10-14 13:14:29 1
  •  < 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

Alternative for basename using grep to extract file name
Here's a bash version.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

Awesomeness Confirmation Bias

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

Get your outgoing IP address

ensure your ssh tunnel will always be up (add in crontab)
I find it ugly & sexy at the same time isn't it ?

exec chmod to subfiles
Using `-exec cmd {} +` causes find to build the command using all matching filenames before execution, rather than once per file.

Go to the next sibling directory in alphabetical order, version 2
Another version based on linkinpark342's contribution. Sometimes you have to browse your way through a lot of sub-directories. This command cd to the next sub-directory in alphabetical order. For example, if you have the directories "lectures/01-intro", "lectures/02-basic", "lectures/03-advanced" and so on, and your PWD is "02-basic", it jumps to "03-advanced".

ZSH prompt. ':)' after program execution with no error, ':(' after failure.
sorry for my english

Search for files in rpm repositorys. (Mandriva linux)
Look for an rpm that supplies a specific file that you don't yet have installed. extremely useful when you need something and don't know where it is.. or what its called. note: uses grep like syntax.

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: