8 ms·
SSH Commands / Tricks
- jeberle 16y ago26. $ ~<Ctrl-Z> # suspend current SSH session Very useful.
- vog 16y agoThere's a little typo in item 5: "Will allow you to mount a folder security over a network." I guess the author meant instead: "Will allow you to mount a folder securely over a network."
- chrisbroadfoot 16y agoSeems to be down. Text only cache: http://webcache.googleusercontent.com/search?q=cache:http://blog.urfix.com/25-ssh-commands-tricks/&hl=en&strip=1 http://webcache.googleusercontent.com/search?q=cache:http://...
- pshirishreddy 16y ago^+1
- ronnier 16y agoMy cache got it also, and it's easier to read: http://viewtext.org/article?url=http://blog.urfix.com/25-ssh-commands-tricks/ http://viewtext.org/article?url=http://blog.urfix.com/25-ssh...
- pixdamix 16y agoThis list is missing sshuttle: https://github.com/apenwarr/sshuttle https://github.com/apenwarr/sshuttle sshuttle is a transparent proxy server that works as a poor man's VPN. Forwards over ssh. Doesn't require admin access. Works with Linux and MacOS. Avery Pennarun is a Hero :)
- pmjordan 16y agoWow, this is fantastic, thanks! I was looking for something like this a while ago and the closest I could find was transocks, which is Linux-only, not overly stable, not actively maintained, and TCP-only.
- pixdamix 16y agosshuttle is currently TCP-only i remember seeing some people discussing about UDP, and DNS forwarding on top of sshuttle but it hasn't gotten very far.
- Macha 16y agoWhat does this do that ssh -Dport user@host does not?
- pixdamix 16y agoForward transparently your traffic using iptables. So, if you use sshuttle on your gateway all the tcps connections to the specified subnets are forwarded using ssh for the gateway and all the machines using that gateway. You can do this # sshuttle -v -r user@host:443 10.0.0.0/8 # ssh user@10.0.0.138 Connections to 10.0.0.0/8 goes through ssh automatically.
- Estragon 16y agoHow can something like this work without admin access? Mucking around with network routing using requires root, doesn't it?
- pixdamix 16y agoIt require root access on the client, on the server it only needs ssh and python >= 2.3
- dedward 16y agoThanks - that's awesome. Pandora is back. Nice piece of code - tons of interesting possibilities there.
- dedward 16y agoI wish this would automatically omit locally attached networks -although easy enough to do from the command line.
- deleted 16y ago[deleted]
- scrrr 16y agoUseful post! Does anyone know: Is it recommended to mount a directory via sshfs? My idea: Mount whole server filesystems into /mnt/servers/<server_ip> ... and then conveniently work with it using desktop tools. Can it be done? What are the downsides to that?
- woogley 16y agoThe biggest thing to remember is that any command you run will be in a local context. For example, if you want to do things like updating a SVN repo that's located on the server you've mounted, you should SSH directly into the server and perform it. Otherwise, your _local_ SVN software will try to read in tons of files FROM the server to establish changes in the checkout before it can even try to commit. This can be very slow!
- askedrelic 16y ago^^Very good point. On OSX with MacFuse and SSHFS, I've done plenty of remote work before on LAN servers and "internet" servers. It definitely works, but is slow. But for being able to open up a "local" file in Vim/text editor and then save it, the only time you are hitting the network is during the save and that can be slow. Transmit 4 integrated this functionality into their FTP client, auto-mounting of SSH connections, but it definitely seems more crashy than MacFuse to me.
- fragmede 16y agoIf remote editing vim is your only requirement, it should be noted that up-to-date versions of vim will handle scp://, as in "vim scp://hostname/file_to_edit". (Emacs users have Fish) (you should already have ssh keys setup)
- Nick_C 16y agoThanks for that. You've just removed 90% of my use cases for opening an actual shell on the remote server. I've been using vim for a decade or more. I guess it's a salutary lesson for experienced users. I should read the Changelog more carefully when upgrading.
- yatsyk 16y agocool list, thank you! Previous ssh fu posts: http://news.ycombinator.com/item?id=1536126 http://news.ycombinator.com/item?id=1536126 http://news.ycombinator.com/item?id=874666 http://news.ycombinator.com/item?id=874666 http://news.ycombinator.com/item?id=1624010 http://news.ycombinator.com/item?id=1624010
- alien_acorn 16y agohttp://news.ycombinator.com/item?id=1923170 http://news.ycombinator.com/item?id=1923170
- MrMatt 16y agoInteresting stuff, but can you clip the number from the title, please?
- ljlolel 16y agoI have been looking for solutions to some of these things forever: 21) Have an ssh session open forever autossh -M50000 -t server.example.com ‘screen -raAd mysession’ Open a ssh session opened forever, great on laptops losing Internet connectivity when switching WIFI spots. 24) Transfer SSH public key to another machine in one step ssh-keygen; ssh-copy-id user@host; ssh user@host This command sequence allows simple setup of (gasp!) password-less SSH logins. Be careful, as if you already have an SSH keypair in your ~/.ssh directory on the local machine, there is a possibility ssh-keygen may overwrite them. ssh-copy-id copies the public key to the remote host and appends it to the remote account’s ~/.ssh/authorized_keys file. When trying ssh, if you used no passphrase for your key, the remote shell appears soon after invoking ssh user@host. 25) Copy stdin to your X11 buffer ssh user@host cat /path/to/some/file | xclip
- wladimir 16y agoVery useful indeed, some of those I've been wondering about for ages.
- danielh 16y ago25a) Copy stdin to clipboard on Mac ssh user@host cat /path/to/some/file | pbcopy
- xtacy 16y agoTo keep an ssh session forever, you could also add the following line to ssh_config. ServerAliveInterval 10 The client sends a keepalive packet every 10 seconds.
- phreeza 16y agoI know its a small difference, but I am happy this title doesn't imply I don't know these tricks yet, as some articles of this kind tend to do.
- wildmXranat 16y agoTech folks are sensitive to arrogance and jabs at pride in context of knowledge. It seems like every other top ten list poster seems to be standing on the shoulders of giants we never knew of.
- yoak 16y agoThat's an excellent litmus test on whether there is likely to be anything actually valuable there. On the other hand, I wonder how much more traffic they might get from the people who visit just to affirm, "I do too know them..." :-)
- vog 16y agoThe site is currently down. Why is it so hard for most blog software to do the most basic thing of the web: delivering static content?
- shiftpgdn 16y agoBecause the author made the same mistake so many Wordpress users do which is going absolutely crazy with add-ons. I managed to get the page to load after about 3 minutes and I can count at least 8-9 add-ons he is using that are sucking up tons of server resources. The owner of this blog would be extremely well served by removing unnecessary add-ons and installing something like WP Super Cache to serve content significantly faster and lower the server load. For security he might want to relocate the admin login URL as well since he still has it set to /wp-admin/ .
- amackera 16y agoWhat additional security does relocating the admin login buy?
- jimwise 16y agoLike running sshd on another port (to stay on topic), it doesn't make the service more secure against someone who knows it's there, but it makes it less visible to automated scripts probing the standard location for known bugs.
- epo 16y agoThen again, for security he might want to use something else. Is it only me who is amused by the irony of someone using a system with such a poor security track record to talk about ssh which is intended to provide secure connections?
- wyclif 16y agoWhy does this submission continue getting voted up when the site has been down all day today?
- kree10 16y agoOne cool application of ssh port forwarding missing from the list is https://github.com/progrium/localtunnel https://github.com/progrium/localtunnel It lets you temporarily give a behind-the-firewall web server a public, port 80 URL.
- yogsototh 16y agoI use ssh -D9999 user@remotehost.com And now I have a local SOCKS proxy running. I just have to change the proxy configuration in my browser using SOCKS4a at localhost:9999 and I can surf as if I were on remotehost
- pixdamix 16y agotsocks might help also for apps which do not have native socks support.
- derwiki 16y agoi use ssh -D plus FoxyProxy on a daily basis, it's made my life a whole lot easier!
- arihelgason 16y agoThis is really useful. And if you do ssh -ND 9999 it doesn't open a shell. This may stop you from accidentally shutting down your tunnel thinking it's just another ssh session.
- softbuilder 16y ago> i think that is the fastest and best way to migrate a DB to a new server! Except that your mysql password is now in your history?
- IChrisI 16y agoIsn't this what history -d is for? I always delete passwords and important information from my bash history.
- mdwrigh2 16y agoJust put a space before you execute the command, then it doesn't get saved in history. Alternatively, delete it from your history file as the other commenter suggests.
- varjag 16y agoAlso, use ~. to terminate a stalled session.
- 1amzave 16y agoThe tilde-escape offers significantly more than just termination, actually. Hit '~?' for the available escape sequences: Supported escape sequences: ~. - terminate connection (and any multiplexed sessions) ~B - send a BREAK to the remote system ~C - open a command line ~R - Request rekey (SSH protocol 2 only) ~^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.) If you open the command line (~C), another '?' shows its available commands: ssh> ? Commands: -L[bind_address:]port:host:hostport Request local forward -R[bind_address:]port:host:hostport Request remote forward -KR[bind_address:]port Cancel remote forward
- raffi 16y agoOne of my favorites, from: http://www.phrack.org/issues.html?issue=64&id=4&page=2 http://www.phrack.org/issues.html?issue=64&id=4&page... See: An almost invisible ssh connection ssh -T user@host /bin/bash -i This connects you to a box with no TTY allocation. If someone types 'w', they will not see your connection.
- alnayyir 16y agoOkay, you've done the trick, now what's the reveal? How do you readily detect someone who has started their shell without TTY allocation?
- daten 16y agoThe sshd process for your connection is still present on the server and looks like: "sshd: username@notty". You can find it easily with a grep of running processes. ps aux | grep sshd.*notty
- timtadh 16y agoif you are running sshd on port 22 this will show you all connections going into it sudo lsof -i :22 you can then reverse what people are doing based on the pids lsof gives you. [edit: using ps ax | grep sshd also works but you can't see where they are connecting from. [+1 daten]]
- astrim 16y agoThis is much better ssh -t user@host screen -ln since you get a full fledged shell with job control and everything
- mvalle 16y agoWhen I first got my netbook, I sometimes set up an ssh media server to stream music from my main computer to my netbook like this: ssh user@host cat /path/to/music-collection | mplayer
- konad 16y ago> When ssh is the foundation of your security architecture, you know things aren't working as they should. Rob Pike http://interviews.slashdot.org/article.pl?sid=04/10/18/1153211 http://interviews.slashdot.org/article.pl?sid=04/10/18/11532...
- seanl 16y agoIf you read the context, this isn't really a specific criticism of ssh, but rather a general criticism of Unix's network model (or lack of it). Maybe we should all be using Plan 9, but as we're not ssh helps a lot.
- konad 16y agoI know, I'm a long time plan9 user, I know what it could be like.
- amccloud 16y agoThey may want to change their DB username and password ASAP. http://blog.urfix.com/wp-config.php http://blog.urfix.com/wp-config.php I can see their config in plain text.
- jackowayed 16y agoIf you're on OS X, you can get ssh-copy-id through homebrew. (And if you're on OS X and not using homebrew, go install it now: https://github.com/mxcl/homebrew https://github.com/mxcl/homebrew )
- marchdown 16y agoIt's clunky. How is it better than compiling for yourself or using Apple-blessed MacPorts?
- jackowayed 16y agoCompiling it yourself takes a lot more work than `brew install ssh-copy-id`. Here's a pretty good expression of the main complaint I've heard about MacPorts: > The system [homebrew] is much better than MacPorts, the idea is that for example, Mac OS X comes with python installed. Brew will try to use the default python installation instead of trying to make it's own in /usr/opt/whatever ... so, homebrew premise, is to respect the Mac OS X installed packages and use them to it's favor + respecting the Mac OS X structure ( don't re create a whole new structure like fink and mac ports ) - http://stackoverflow.com/questions/189912/what-package-manager-do-you-prefer-for-mac-os-x http://stackoverflow.com/questions/189912/what-package-manag... An added bonus is that things tend to install way faster because it's not compiling all of this stuff that OS X came with.
- marchdown 16y agoLast time I tried to use it I was burned when it came to removing packages. Sure, I can remove them by hand, but then what good is my package management system? The hairier installation is, the more configuration files it creates and modifies all over the system, the more urgent is the need for reliable management system. And there are packages that can't not write all over the system. SSH is one. Sage's another.
- deleted 16y ago[deleted]
- samratjp 16y agogithub does some impressive backend work with SSH - I was amazed when I read about their architecture https://github.com/blog/530-how-we-made-github-fast https://github.com/blog/530-how-we-made-github-fast