Wikipedia:Reference desk/Archives/Computing/2015 October 2

= October 2 =

What makes ssh time out?
When I log into an Ubuntu Linux box on my home network via ssh (from a Cygwin/Windows box nearby), I find that my sessions time out after some large amount of time (at least 30 minutes...maybe hours?) when I'm not actively using them. When I do the same thing to a Linux box on the other side of the planet run by my ISP, the timeout is MUCH shorter - so evidently this timeout can be adjusted on the server-side. How do I do that? SteveBaker (talk) 14:02, 2 October 2015 (UTC)


 * On my OSX system,  returns in part:

ClientAliveCountMax Sets the number of client alive messages (see below) which may be sent without sshd(8) receiving any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the session. It is important to            note that the use of client alive messages is very different from TCPKeepAlive (below). The client alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable. The client alive mechanism is valuable when the client or server depend on knowing when a            connection has become inactive.

The default value is 3. If ClientAliveInterval (see below) is set to            15, and ClientAliveCountMax is left at the default, unresponsive SSH clients will be disconnected after approximately 45 seconds. This option applies to protocol version 2 only.

ClientAliveInterval Sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client. The default is            0, indicating that these messages will not be sent to the client. This option applies to protocol version 2 only.


 * This suggests to me that adding the lines


 * to /etc/ssh/sshd_config (or someplace analogous)
 * should give you an timeout of 30 minutes. I have not tested this and know nothing of the vagaries of different sshd distributions, versions, etc. SemanticMantis (talk) 14:44, 2 October 2015 (UTC)


 * And, for cases where you are not the server administrator, you can configure the client to perform keepalives: ssh_config may include the ServerAliveInterval option:

ServerAliveInterval Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server, or 300 if the BatchMode option is set. This option applies to protocol version 2 only. ProtocolKeepAlives and SetupTimeOut are Debian-specific compatibility aliases for this option.


 * It's up to you to decide if you want to configure the server, or the client, or both... there are usually no problems if keepalives are sent in both directions.
 * Nimur (talk) 15:01, 2 October 2015 (UTC)


 * I've always wondered about this, but (slothful me) never delved into it to figure it out. The poor-man's solution I sometimes use is a little one-off ad-hoc keepalive pinger, invoked on the remote system:




 * (where  is a little hex-to-binary filter that's been sitting in my personal bin directory since 1981 or so).  This sends an invisible null character down the line once a minute, and usually works to keep the connection from timing out.  (And even if I did know the magic sshd option to keep sessions from timing out, but the relevant machine wasn't under my control, I might still choose to use this user-level workaround.) —Steve Summit (talk) 13:17, 3 October 2015 (UTC)

Mass rename / format files
Somehow, I've managed to remove the name and extension of over 400 photos and video files. So I'm stuck with files name 1,2,3 without the corresponding prefix to denote what type of file they actually are. Is there some way I can undo this or set them back up.

Trouble is, I can't really determine which files are videos or just pictures. --80.195.27.47 (talk) 15:16, 2 October 2015 (UTC)


 * Yikes! Realistically, it is probably faster for you to use a batch renaming tool to fix the bulk of the file names and extensions; then manually sort these files and rename the rest one-by-one, using guess-and-check to fix any incorrect file extensions.  If you're really proficient, tools like file (command) can make educated guesses about file types... a script can wrap that command and automate your work... but I'd bet you'll spend more time learning to use it efficiently than manually modifying 400 files.  If this is a problem that you never expect to need to solve again, the slow and arduous process of hand-correcting each file might really be the fastest way out.
 * If you are on Windows (... I make this presumption based on the new filenames you accidentally created!)... you might find the software mp3tag useful. Canonically, it is designed for batch modification and renaming of music files, but if I recall correctly, it will happily rename any other file type.  It has a "regular expression"-style, wildcard-substitution file naming utility that will be more familiar to Windows users than many of the more general purpose, Unix-esque batch file manager softwares.
 * Nimur (talk) 17:07, 2 October 2015 (UTC)
 * I suppose you did not wanted to say prefix, but suffix, in reference to the file extension. Scicurious (talk) 18:56, 2 October 2015 (UTC)

Batch renaming is the easy part. Figuring out which are which is more challenging. Taking the harder part first:

The simplest solution that might work, depending on your OS settings and the original filetypes, would be to rename all of the files to be images (e.g. .jpg) then load thumbnails in your file explorer/viewer. If you're lucky, the ones that aren't images won't display properly. If they all display, try the same technique but with a video extension. If that works, skip the next paragraph.

If that didn't work, sort the files by size. This will cut down on some of the guesswork. If they were all taken with the same camera with the same settings, the size of the images will be relatively similar. In some cases, they'll might even be the same. Video files won't be so consistent, so look for patterns, moving those that look like video files out to a separate directory. You'll have to do some trial and error for videos that are about the size of images.

The renaming part. Operating under the assumption of Windows, open the directory with your presumed images. Holding CTRL-SHIFT, right click in an open part of the directory (i.e. don't click on a file) and select "Open command window here". In the console, you want the "rename" command. So if all of your files have no extension and you want them all to be .jpg, just type "rename *. *.jpg" (without quotes). If they're all jpg and you want them to be .mov, you would do "rename *.jpg *.mov". Good luck! &mdash;  Rhododendrites talk  \\ 22:00, 2 October 2015 (UTC)
 * Rhododendrites' suggestion is a good one. To make it even easier, use XnView as your file browser. It will display a thumbnail for an image named "*.jpg" whether it's a jpeg or a png, but it will only show relevant information (confirmation of file type, geometry) if you've named it correctly. So there you have sorted your files into jpegs, pngs and the rest. Then sort by size from XnView, which will enable you to mark a large group of files of the same type. Move the files into separate subdirectories from XnView. I believe XnView handles some raw formats too, such as Canon's *.CR2. If you then name the remainder *.mov, thumbnails will appear, but no information. Move to "Mov" subdirectory. I've only tried this with *.mov's recorded with a Canon SLR. Do the renaming from the command line, as described above. I just did this with a bunch of files that I had copied from my photograph directory for the experiment. A mixture of 170 jpegs, pngs and movs, that I had renamed 1001, 1002, 1003 etc, and it took less than 15 minutes. edit: Worked with AVI's from another camera, too. --NorwegianBluetalk 22:15, 4 October 2015 (UTC)