×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

The Elusive Command Alias Function?

Cliff posted more than 8 years ago | from the enhanced-terminal-software dept.

114

Meph_the_Balrog asks: "I work as a helpdesk jockey for a company that manages over 1200 linux based servers, across a huge area. Currently we use a Windows SSH client to provide remote server support, and I don't have the weight to convince management to deploy alias scripts to all of the servers we support. I admit this question may seem frivolous to some, perhaps dangerous to others, so I have a twofold question. Do any of you out there use a Windows based SSH client that supports command aliasing? If you have strong objections to this sort of technology, what inherent problems do you see with it?"

cancel ×
This is a preview of your comment

No Comment Title Entered

Anonymous Coward 1 minute ago

No Comment Entered

114 comments

Huh? (0)

Anonymous Coward | more than 8 years ago | (#14820331)

I must be missing something important. Does the poster mean alias scripts in the sense of alias statements in a .bashrc? If so, what does that have to do with windows ssh?

Re:Huh? (0)

Anonymous Coward | more than 8 years ago | (#14820664)

What you're missing, is me shooting my load into your ma from behind while she was bent over your bed. Your ma showed me the pictures of you and her making your little brother/son too, your little cock barely able to penetrate that hallway she calls a snatch. Yeehaw, you stuck it in your grandma, yahoo you fucked your grandpa too.

Re:Huh? (1)

B'Trey (111263) | more than 8 years ago | (#14820994)

I'm not sure what he means either. However, I suspect that SecureCRT does what he wants. You can configure a login script to run when you connect, within which you can set up shell aliases. You can run scripts manually, within which you can do whatever you like, and you can configure keys to send whatever strings you like. One of these should cover whatever it is that he's asking how to do.

Huh? (1)

choudesh (880042) | more than 8 years ago | (#14820348)

Alias scripts? Not sure what the author wants, but I see no problems in Aliases. If I am on the same brainwave, alias ls="ls -la", then I don't see any issues. I mean aliases are there for a long command with parameters or unknown or hard to remember commands. alias df="diskfree" for example. ok, bad example, but you get the jist.

I get what he wants. (3, Informative)

Valdrax (32670) | more than 8 years ago | (#14821563)

Okay, I get it now. Here's what the guy wants:

He has no power to install his favored command aliases on all of the machine he has to administrate. He wants to have an SSH client (that he can run on Windows to connect to the Linux machines) that will interpret what he types and substitute aliases so that he doesn't have to set up his favored commands every time he logs into a system.

I don't know if you can set an SSH session into a line-based instead of keystroke-based communication mode. By default, it sends messages to the remote server after every keystroke and not after enter is hit at the end of a line -- otherwise using curses-based applications would really, really hurt as would using tab-completion, vi mode, and other advanced shell features. If this can't be done, then a client couldn't interpret your commands before you send them.

I don't forsee anyone providing this functionality because the demand is so low. This is the kind of thing that the remote end is expected to handle for you.

Re:I get what he wants. (1)

Compholio (770966) | more than 8 years ago | (#14822771)

1) Create a plain text file with all the alias commands:

alias ls="ls -alF"
alias nano="nano -w"
...

2) Open connection to server in client of choice
3) Open file in notepad
4) Select All
5) Copy selection
6) Paste in connection window

Re:I get what he wants. (1)

Valdrax (32670) | more than 8 years ago | (#14823364)

7) Imagine doing this 8-9 times every single day.
8) Sob yourself to sleep after tearing out all hair.

Re:I get what he wants. (1)

illumin8 (148082) | more than 8 years ago | (#14823020)

He has no power to install his favored command aliases on all of the machine he has to administrate. He wants to have an SSH client (that he can run on Windows to connect to the Linux machines) that will interpret what he types and substitute aliases so that he doesn't have to set up his favored commands every time he logs into a system.

This is a really easy problem to answer. Follow these steps in order:

1. Make a list of all the servers and put it in a text file.
2. Make your .bashrc in your home directory on one server contain all of the aliases that you want to be on all the servers.
3. Type this command (it works a lot better if you've setup ssh key authentication to all of your servers):

for server in `cat serverlist.txt`; do scp .bashrc $i:; done

What this does is simply iterate through your server list and copy your .bashrc (bash startup file) to every server that you log in to, in your home directory.

Let me know if this helps.

Re:I get what he wants. (1)

illumin8 (148082) | more than 8 years ago | (#14823041)

for server in `cat serverlist.txt`; do scp .bashrc $i:; done

Whoops, I meant:
for server in `cat serverlist.txt`; scp .bashrc $server:; done

Re:I get what he wants. (1, Informative)

Anonymous Coward | more than 8 years ago | (#14829016)

This time you forgot "do", but even then you would get:

sh: command line to long

Not that many servers in your data-center, are there? :-)

Try
while read server; do scp .bashrc user@$server:; done serverlist.txt

(because I wouldn't want my username duplicated for every server in the serverlist and I tend to avoid using cat without reason).

Why anyone would use bash though is beyond me. My advice: Use something that you know will always be available by default, not something mostly used by Linux-users.

Re:I get what he wants. (2, Informative)

Valdrax (32670) | more than 8 years ago | (#14823420)

The guy's not too stupid to figure out how to copy his aliases everywhere. He doesn't have permission to do so. That why both he and I both said so (including in the text you quoted).

I am all too familiar with his conundrum, especially when it comes to being forced to work with inferior tools. I work in an environment where I am responsible for keeping production systems running, and I don't have admin install privileges. Even our admins don't have the political power to change things without serious peer-review and management approval. This is the way and enterprise-level IT organization has to work. Making changes in production without verification and authorization can result in revenue loss or loss of data that you may one day be required by court to cough up.

Re:I get what he wants. (1)

jdray (645332) | more than 8 years ago | (#14824113)

He (and you) doesn't even have the power to modify his own .profile, .bashrc and other environment files? If he's logging in as a "generic" userid, that should be addressed as a significant security hole first.

Re:I get what he wants. (1, Insightful)

Anonymous Coward | more than 8 years ago | (#14824214)

With good key management lots of role accounts are the right way to go. Create accounts for semi-root, one for read-only logs access, one for daemon control, etc. Give certain people different role access to different machines by copying their public keys appropriately and you have a very secure and easily managed infrastructure.

Problem is, I happen to like vi-mode bash (set -o vi) but everyone would kill me if I put that in a .bashrc file on a few hundred machines for the debug role account.

Ya dig?

Re:I get what he wants. (1)

merlin_jim (302773) | more than 8 years ago | (#14826686)

He (and you) doesn't even have the power to modify his own .profile, .bashrc and other environment files? If he's logging in as a "generic" userid, that should be addressed as a significant security hole first.

Not sure about the original poster, but we're doing (voluntary) Sorbanes-Oaxley compliance. I'm not even allowed to LOGIN to the production environment unless I submit a plan of work I intend to do, including risk, ways to avoid them, backup plan, concurring business stakeholders, etc etc. There is an emergency approval procedure, but in reality there are very few emergencies of that scale...

Re:I get what he wants. (1)

illumin8 (148082) | more than 8 years ago | (#14827585)

The guy's not too stupid to figure out how to copy his aliases everywhere. He doesn't have permission to do so. That why both he and I both said so (including in the text you quoted).

If he has a user-level account on the box, then he has permission to do what I wrote. And if he doesn't have a user account on the box, then how would he login in the first place. None of the stuff I asked him to do requires root.

Re:I get what he wants. (2, Insightful)

Valdrax (32670) | more than 8 years ago | (#14828307)

There are two scenarios that I can think of off the top of my head could prevent him from doing so:

1) He doesn't have permission to modify his own user account. Unlikely, but possible -- especially if /home is deliberately kept free of space or he's not given an actual home directory to prevent user customization and all he has is the shared shell resource scripts in /etc.

2) He's got to use several shared administrative accounts (like root or various accounts for specific services), or the account he has to use is shared with production processes that might be impacted by adding aliases willy-nilly without knowledge of the whole of all command runs by the system. That's bad security, but it's probably not his design.

I have to deal with both of these problems at my job. I don't have an actual home directory on most of our test servers due to a lazy IT department and immense bureaucratic red tape in getting it fixed, so I'm stuck using the main production user on the test box, and I can't customize it. In actual production, no one is allowed to use this particular ID for accountability purposes, but on a different system we all have to use a different shared production ID which hasn't been obsoleted to do anything. Both of these scenarios are irritatingly bad and beyond my ability to do much about.

At any rate, it's safe to assume from his description that he doesn't have permission to do what you suggested. Reread the article text. He's a "helpdesk jockey" without "the weight to convince management to deploy alias scripts to all of the servers [he supports]." The requirements presented explictly state that your solution is not allowed.

Sorry, try again. The real world of business sometimes sucks in ways that common sense suggests it wouldn't.

Re:I get what he wants. (0)

Anonymous Coward | more than 8 years ago | (#14823270)

Have you ever played a MUD!? All you need is to pipe a MUD client through SSH.

It's not even complex. And because you're wondering, they hold your commands in a line buffer and only transmit it when you hit enter. But yeah, that could be odd for some curses applications, but then I'd just make the numpad into a bunch of macros that send the proper keystrokes.

It's not rocket science.

Re:I get what he wants. (1)

a_ghostwheel (699776) | more than 8 years ago | (#14823880)

SecureCRT [vandyke.com] supports ActiveX scripting which means you can useany scripting language supported by WSH on your machine (like, say, ActivePerl). I think it will accomplish goal.

Re:I get what he wants. (2, Interesting)

CarrotLord (161788) | more than 8 years ago | (#14826042)

If this really is what he wants, and it seems the most logical interpretation, then I'd suggest simply placing a script like .my_aliases on each server, and then running ". .my_aliases" after each login.

However, I have a STRONG aversion to lots of aliases, particularly for someone learning systems administration. When I first started using unix, the sysadmins in the Engineering department had set up a bunch of DOS-like aliases on our servers, so we would feel more at home. We came to depend on these, and a few non-DOS aliases too. I think some were there to make csh look more like sh, or vice versa.

The problem came when I went to use a unix machine in the Computer Science department, which didn't have these aliases (I guess the CS students were considered clever enough to learn Unix, whereas the Engineering students expected everything to be DOS). I was lost for some time, and needed to copy the aliases file over (and just finding that took me ages, as I wasn't familiar with /etc), in order to use the system, even for things like ls. I then asked my local guru about this, and he recommended that I just stick to the defaults, so I'd be able to move between systems without pain.

Since then, and 10 years of sysadminning later, I've got a huge aversion to customising environments. For eg, I always use sh (well, ksh), as it's always available and is always installed in the root filesystem. Likewise, the reason every sysadmin should know vi is because it's always there (apart from the fact that it's better for quick edits of small files than emacs). I tend to avoid vendor-specific tools, as I have needed to move between Solaris, IRIX, Linux and BSD too often to "reprogram" my fingers each time. Obviously, it depends on your situation, and now that I have been using Solaris exclusively for about three years, I've become a little less flexible, but generally, I try to stick to the lowest common denominator, and just be really good at it.

Re:I get what he wants. (1)

nri (149893) | more than 8 years ago | (#14827834)

"CS students were considered clever enough to learn Unix, whereas the Engineering students..."

ROTFLMAO. Since when has a comp sci degree required a higher gpa then an electrical engineering degree.

The EASY way is this... (0)

Anonymous Coward | more than 8 years ago | (#14822371)

Use a MUD client. MUD clients use telnet. They have aliases (for MUDding, but, you can use them for other purposes). You can even set triggers & crap to capture information.

If you need SSH, just have SSH forward a port for the MUD client to use [ssh.com].

There are tons of free MUD clients, Google for them. Tinyfugue, MudMaster, zMUD, whatever you want to use.

What do your servers support? (1)

roystgnr (4015) | more than 8 years ago | (#14820366)

If they've got a command line HTTP or FTP client installed, then you don't need to "install" your alias script, just paste a command like

`lynx -source http://someserver.com/with/my/script [someserver.com]`

(note the backticks) when you first log in.

Re:What do your servers support? (1)

AlXtreme (223728) | more than 8 years ago | (#14822667)

Lets not think about what would happen if someone else ever had write access to that remote script...

With a bit of (bad) luck, he'd be running that script as root... *shudder*

Re:What do your servers support? (1)

roystgnr (4015) | more than 8 years ago | (#14824478)

Lets not think about what would happen if someone else ever had write access to that remote script...

The same thing that would happen if someone else ever had write access to a special ssh client binary you use, or even to your local configuration files: he'd then be able to take over any account you logged into. If you have reason to think your ssh client computer is more secure than any file service you can write to, you don't have to paste a "run this alias script" command, you can just copy and paste the whole script from a file on the client.

Re:What do your servers support? (1)

WWWWolf (2428) | more than 8 years ago | (#14826494)

Sort of clever, but it'd be infinitely easier and more efficient to put that in a network drive, then put ". /mnt/thatthingy/etc/aliases.sh" in their ~/.bash_profile. Pulling the thing with Lynx is kind of silly.

Re:What do your servers support? (1)

roystgnr (4015) | more than 8 years ago | (#14827689)

Sort of clever, but it'd be infinitely easier and more efficient to put that in a network drive, then put ". /mnt/thatthingy/etc/aliases.sh" in their ~/.bash_profile. Pulling the thing with Lynx is kind of silly.

I agree, but the requirement that you can't install your script on the servers you administer is pretty weird to begin with. If he's not allowed to install a script, he probably isn't supposed to edit .bash_profile or mount network drives either - besides, if he could edit .bash_profile he could just put alias commands in there!

So, I tried to come up with solutions that don't require changing anything in the accounts' config files. Ask a silly question, get a silly answer.

Why not.... (1)

MaskedSlacker (911878) | more than 8 years ago | (#14820380)

Why not just use .bash_profile files with alias cmdyoulike='cmdyouwant' ?

Re:Why not.... (1)

netsharc (195805) | more than 8 years ago | (#14820837)

Probably because as he said he doesn't have the power to deploy this script to all the servers they manage?

Re:Why not.... (1)

jrockway (229604) | more than 8 years ago | (#14824698)

It's a freaking bash configuration file. Every user has one in their "home directory". If they are deviating this far from standard UNIX practices... then... I don't even have anything to say.

You ssh to your account, your .bash_profile loads, you do your work, then you log out. I can't imagine how anyone could not be doing it like this.

Re:Why not.... (1)

silverdirk (853406) | more than 8 years ago | (#14825304)

Do you not get it? he has TWELVE HUNDRED MACHINES that he would have to put this .bashrc on. TWELVE HUNDRED MACHINES. Shall I say it again? I think the idea is that he might not even have a personal profile on them, since then every tech's profile would be replicated on TWELVE HUNDRED MACHINES. More than likely, he logs in as some "admin" user, and then fixes whatever is wrong with the box. I really can't imagine a hosting company setting up a profile for each of their helpdesk employees on each machine.

You could argue that they should be using some kind of LDAP deal, but the machines might be spread accross the net, and/or they might just not want to bother with the extra setup involved. So, the question is whether there is a way to get his personal settings installed from his client. I imagine he might also have trouble with sub-shells.

So, my suggestion- assuming he isn't allowed to add files to the machines, I would reccomend a complete wrong-minded hack on the windows end to get things pasted into the client every time he logs in ;-)

For instance, you could write a nice little Delphi program (or VB, *sigh*) that would register a system hotkey, and when triggered would copy some text into the clipboard and paste it into the active app.

Or, the less technical approach would be to have a copy of notepad open at all times with your bash commands, and then just alt-tab,ctrl-c,alt-tab,ctrl-v each time.

Hopefully someone somewhere on this discussion knows of a client that does an automatic batch of commands when it logs on ;-)

Re:Why not.... (1)

Malor (3658) | more than 8 years ago | (#14825370)

They probably do, but they must have a lot of admins for 1200 servers. If they're all logging in as root (standard practice, albeit suboptimal), then they'd all be sharing a .bash_profile. Probably, management's fear of an alias messing up a real admin is higher than their desire to please a help-desk guy.

Submitter: SecureCRT from VanDyke Software (about $90 if I remember correctly), will support login scripts. That would solve your problem nicely.

If you can't afford that, or aren't allowed to install it, you could download your aliases over a network connection each time you connect to a machine.

It would be better to run it over ssh copy than HTTP, so that it's not traveling in plaintext. A command like:

eval `ssh user@scripthost "cat /path/to/scriptfile"`

would do what you needed. This command would simply cat a remote file over an SSH connection.... which eval then executes. You'd have to host it on a machine that all the servers could access. Depending on your security setup, that could potentially be difficult.

You could get fancy and set up agent forwarding if you wanted to save typing the extra password. Sadly, agent forwarding can be something of a security risk, so it may be disabled on your servers. I'd suggest not doing that without getting explicit permission from the more senior people.

Remember that you need to secure the machine hosting the script at least as well as the most secure machine from which you'll be running it. If the script is compromised, any machine on which you run it will be also.

Re:Why not.... (1)

Syberghost (10557) | more than 8 years ago | (#14827394)

It's a freaking bash configuration file. Every user has one in their "home directory". If they are deviating this far from standard UNIX practices... then... I don't even have anything to say.

You ssh to your account, your .bash_profile loads, you do your work, then you log out. I can't imagine how anyone could not be doing it like this.


In many large production environments, especially in systems that fall under SOX 404 restrictions, people don't have write access to their home directories. Often they have shared home directories.

Replicated ssh commands (1)

HunterWare (128177) | more than 8 years ago | (#14820436)

yeeesh, I'm not sure you want to be doing this stuff if the solution isn't pretty clear. " ssh hostname 'command' " will execute whatever command you want on the remote machine. Use authorized_keys on the machines so the ssh goes through without a hitch. Use your scripting language of choice to send each command in a sequence to a list of machines.

If you want to get really funky then add interaction to the script to allow inputing commands. If you are actually messing with multiple machines I submit it is quite dumb to do these operations with a console. You don't want input error to be a factor in a production environment. You do want to test the sequence of commands on a single box and then run them in replication.

Re:Replicated ssh commands (0)

Anonymous Coward | more than 8 years ago | (#14824022)

" ssh hostname 'command' " will execute whatever command you want on the remote machine.
Dude, I can't tell you how much I wish I had modpoints right now. I've been using ssh for years and never realized that this capability existed. I always figured I needed rsh to do this, and of course few places enable rsh. It's a shame I hadn't seen this sooner, but you've undoubtedly saved me many future hours that I would have spent opening a full shell on a remote host to execute a single command.

Paint me Confused... (1)

ratboy666 (104074) | more than 8 years ago | (#14820463)

You are managing the servers with no write access?

Re:Paint me Confused... (1)

TheCarp (96830) | more than 8 years ago | (#14820933)

No, he is managing machines where he has to get aproval before using that write access. Maybe you have heard terms like "change management" or "production support".

sure he could probably go and do it unilatterally, but thats a move that doesn't have alot of CYA in it. CYA is alot more important in some places than others.

That said its not all about CYA, sure change management processes are often slow, and tedious, and often seem pointless for small changes.... but... nobody ever made a system problem worst by documenting their work.

-Steve

Re:Paint me Confused... (1)

ratboy666 (104074) | more than 8 years ago | (#14821399)

Yes, I expect change management. You know, I used to design run-books.

Now, he has to work within the structure. And, within the structure, scripts can probably be deployed.

Of course, making a script that enters from the keyboard via an SSH client playback macro so it doesn't have to go through the run-book is... kind of borked, no?

If he DIDN'T have write access and was simply collecting information, such a dynamic script may be justified.

If he wants to use this to introduce another management layer without entering it into the run-book, that's another issue.

Now do you understand my confusion, and question?

Ratboy.

Re:Paint me Confused... (1)

Motherfucking Shit (636021) | more than 8 years ago | (#14824057)

Now, he has to work within the structure. And, within the structure, scripts can probably be deployed.
The submitter explicitly mentioned that he doesn't have the pull to get a script deployed across all 1200 servers. If your first thought is "why the hell not, if he's an admin who needs to manage all of these machines?," then I generally tend to agree.

Re:Paint me Confused... (1)

TheCarp (96830) | more than 8 years ago | (#14826533)

Yes.

I sort of assumed that it was more an issue of looking for a solution for a team of admins. You know... like I can put the cool tools I like in my home dir on all the machines I touch, but installing it for everyone else to use requires aproval.

Also, ssh macros shared on a team seems fine to me. Its still only triggered when an admin is using it, and its not installed on the machine. Nobody has to go in as root and start pushing files around (or tell the distribution engine to push it out to the machines)... you just pass it around to the admins as a tool that you use.

I guess whether its an appropriate solution or not depends as much on the details of the policy as anything else. Is it simply an end run around the policy? Its realy hard to tell from the question, honestly, I think its as much a misunderstanding about how ssh works as anything else.

-Steve

What kind of aliases? (3, Insightful)

stevey (64018) | more than 8 years ago | (#14820498)

I'm guessing from the mention of Windows that you're thinking of things like:

alias del='rm'
alias dir='ls'

Hard to say with such a vague question though, especially with the idea that the client must support the aliases. The clients I've used terraterm and PuTTY are the most commonly used, and putty at least doesn't support aliases. (Can't recall terraterm using them either, but I admit I didn't use it often).

Personally I think that having DOS-style aliases is a mistake. Even though they might seem helpful to users of DOS/Windows it can cause problems when people realise the commands, even aliased, don't work in the way that they'd expect.

Unless you could offer a 100% compatible environment it would be best to let people realise that Unix is different and work with it as it should be.

Re:What kind of aliases? (1)

hesiod (111176) | more than 8 years ago | (#14823073)

> it can cause problems when people realise the commands, even aliased, don't work in the way that they'd expect.
> Unless you could offer a 100% compatible environment it would be best to let people realise that Unix is different and work with it as it should be.

Perhaps I don't understand what you are saying, but how would it cause problems that don't already exist? If it is a case of people not understanding UNIX vs. DOS, it would be people not understanding aliases v. not understanding the UNIX command. Eitheir way, it's an education issue. Unless, of course, the aliased command replaces an existing UNIX command (as an extreme example, alias rm='rm -rf /*')

Not that kind of aliases (1)

Motherfucking Shit (636021) | more than 8 years ago | (#14824095)

Maybe I'm just on the same brainwave as the submitter, but it seems like a lot of folks are missing (what I perceive to be) the point. This guy admins a bunch of Linux machines. He does so from a Windows desktop, using a Windows SSH client like Putty or SecureCRT. He has some aliases that he likes to use on Linux; say like a couple of my favorites:

alias h='history | grep -i'
alias nmap='nmap -v -O -sS'

Now, he doesn't want to have to login to 1200 different machines and edit 1200 different .bash_profiles and manually add these aliases 1200 times. He also doesn't have permission to deploy a script to all 1200 servers to set these aliases up for him automatically. What he wants is a way to setup his aliases in his local Windows SSH app, and have them dynamically applied to any server he logs into.

(I don't mean to pick on you Stevey, yours was just the comment I was at when I thought "wait a minute, everyone seems to be mis-grokking the question.")

Re:Not that kind of aliases (1)

stevey (64018) | more than 8 years ago | (#14825114)

The way you read the question seems to make more sense than the way I did.

I'm not sure really how to handle this situation then.

If the OP doesn't have permission to script the copying of some files to /etc/bash_completion.d/, or similar, I guess the question comes down to scripting the addition of the macros on all the client machines via a login script, or some other Windows-magic

That might work out nicely if the users are all in a single Windows domain.

I find the idea, though, of macros for SSH access being applied on the client side a bit disturbing. What if you typed "ls" and the macro changed it into "rm" ?

Re:Not that kind of aliases (0)

Anonymous Coward | more than 8 years ago | (#14830554)

using cygwin ssh:

ssh -t localhost '(echo alias foo=bar; echo alias qux=baz; echo source ~/.bashrc)> /tmp/myaliases$$.sh ; bash --init-file /tmp/myaliases$$.sh ; rm /tmp/myaliases$$.sh'

Don't think so (1)

lexarius (560925) | more than 8 years ago | (#14820514)

That sounds like a horrible idea. I'd hate to have to implement it. What's so hard about tossing out a single script that contains a bunch of alias definitions, and maybe running it in the default login script?

Re:Don't think so (1)

hesiod (111176) | more than 8 years ago | (#14823113)

> What's so hard about tossing out a [...] default login script?

I think the problem with that is that he wants a solution across multiple servers and multiple users. IMWO, I would guess he needs a SSH client that will automatically send a list of commands (contents of your suggested script, from some a central location) after the user is authenticated. But he would have to ensure evereyone's SSH client ran those commands. So I guess it's not a solution at all, unless he could force all of 'his' clients to do the same. At least then, he can change the centralized source to change everyone. That, of course, assumes that he can find a central location that every workstation's SSH client can read that file from (ie, LDAP). Err, I guess getting the servers to read that file would be far easier, which would require the access/convenience that he doesn't have. Uhhh... how about an automated SSH client script that creates the server script? Then all he has to do is log into each one of his servers... all 1200 of them.

How about a corporate-wide memo explaining that UNIX isn't DOS? Maybe some doc links.

Re:Don't think so (1)

lexarius (560925) | more than 8 years ago | (#14824198)

Hmm. At the university here, (at least in the CISE dept), we make good use of NFS. All users have one home, regardless of which server they login to. It would also be easy to place the script somewhere in NFS space. A per-user login script that calls the centralized script could be added to the skel structure so that all new users would receive it. It could be deployed to existing users with a script along the lines of "for each directory in /homes as x, if /homes/x/.login exists, append blah to it. Else, create it and put blah in it". Assuming that "blah" executes the centralized script, this could be even more useful, since you can just add things to the central script later.

Re:Don't think so (1)

hesiod (111176) | more than 8 years ago | (#14825778)

> we make good use of NFS

Yeah, I remembered NFS just after posting, but didn't want to reply to myself. Even though he'd still need to go through all the paperwork, it might still be a good idea for his situation.

Answering The Questions (0)

Anonymous Coward | more than 8 years ago | (#14820531)

Do any of you out there use a Windows based SSH client that supports command aliasing?

No. No one does because aliases are supported in the shell into which you login to via SSH, typically BASH. When you SSH into a Linux machine, you are starting a bash shell process on the target machine. Any aliases that you wish to use will have to be within that shell, not the SSH client.

If per chance you wish to implement an alias on all of your Linux machines, then you should use network shared home directories and put that alias in your /~/.profile. Then, no matter which linux box you log into, you will have your favorite alias available to you.

If you have strong objections to this sort of technology, what inherent problems do you see with it?"

I have no objections to aliases. Tony the Tiger says; They're great!!! I would try to avoid bash scripts that call aliases within the script because they are not portable. Calling MyCoolAlias within a script that performs backups, for instance, will work fine on your box or even the boxes within your department but, the new box that the intern just setup won't have that alias and the script will break so, it's better to use the "longhand" command when writing a bash script.

'alias scripts' ? (1)

ignorant_newbie (104175) | more than 8 years ago | (#14820559)

so - just to make sure we're on the same page here:
Aliases
( from man bash ) allow a string to be substituted for a word when it is used as the first word of a simple command. The shell maintains a list of aliases that may be set and unset with the alias and unaliases builtin commands...
Script
a program written in a scripting language. May be a shell script, perl script, ruby script, etc

So... an alias is something you either set on the command line, or in your shell startup scripts. it's usually something you type a lot, and is used to save keystrokes, or something complicated that you do occasionally and have to look up the syntax for each time. for example, many people create the following alias:

alias ll="ls -al"

so that they just have to type 'll'.

shell scripts are little programs.

In either case, you can write these yourself, and deploy them to your own user accounts on the machines. Assuming, that is, that you actually have your own user account, and that they're not just hading out root to everyone. In which case you have bigger problems than not knowing what an alias is.

Bad idea... here's why (2, Funny)

TheSkyIsPurple (901118) | more than 8 years ago | (#14820646)

>I don't have the weight to convince management to deploy alias scripts to all of the servers we support.

I've only watched one episode of Alias, but it didn't really draw me in. But, irrespective of that, I don't know why you'd want to put the scripts to copyrighted shows on your servers, especially if they are publicly available.

Maybe it's a Linux thing? people just want to do everything on Linux =-)

what are you asking? (2, Informative)

corbettw (214229) | more than 8 years ago | (#14820682)

Are you asking how to set up an alias kind of like this:

ruptime=`ssh $1 '/bin/uptime'`

Then when you want to check the uptime on a remote box, you run:
ruptime remote_host

And do all this from a Windows box?

If that's the case, you should use Putty. The Putty configuration can be set up to run a remote command, linked to a given hostname. Then when you open Putty, just select the proper 'alias' from the list, just like you would any host.

I would expect SecureCRT has a similar function, but I haven't used it in a few years.

Re:what are you asking? (2, Informative)

eric2hill (33085) | more than 8 years ago | (#14820886)

I use SecureCRT [vandyke.com] on a daily basis.

When you're editing the properties of a session, you can check the "Logon script" box and choose a logon script to use for that session. You can do that either per-session, or as a global setting so it happens for all of your sessions.

Your logon script can contain as many aliases as you'd like.

Re:what are you asking? (0)

Anonymous Coward | more than 8 years ago | (#14821288)

Congratulations on a) not being retarded, unlike twenty or so other people who felt it necessary to respond and b) being the only one of the non-retards thus far to actually give the guy an answer.

Re:what are you asking? (0)

Anonymous Coward | more than 8 years ago | (#14823956)

Thanks. You know, I probably won't even get modded up 'cause it's an on-topic post that provides a simple solution to the posters' problem. Oh well, I guess this is Slashdot.

Se lya vi

Helpdesk jockey? (0)

Anonymous Coward | more than 8 years ago | (#14820752)

Judging from how you asked that question, I think I know why you're a helpdesk jockey and not an administrator? ;-)

Re:Helpdesk jockey? (0)

Anonymous Coward | more than 8 years ago | (#14828477)

Judging from your, use of puncutation? I think I know why you!re not an English; major'

huh? (1)

tscheez (71929) | more than 8 years ago | (#14820796)

since an ssh client logs in to a remote computer and the aliases are on the remote machine, local command aliases are not going to help. an unless i totally don't understand the question.

what i can tell you want is a client that will read "dir" as you type it in and on the remote machine run "ls -lh" or something. i have never seen anything that would allow you to do that.

i see no way of setting aliases without deploying it locally to each server, unless you have a roaming home directory.

Re:huh? (1)

hesiod (111176) | more than 8 years ago | (#14823176)

> what i can tell you want is a client that will read "dir" as you type it in and on the remote machine run "ls -lh" or something. i have never seen anything that would allow you to do that.

If it were telnet, a MUD client (eg, GMud) would do what he wants. However, I do not know of any SSH MUDs.

bleh (3, Funny)

Intangion (816356) | more than 8 years ago | (#14820907)

some of the ask slashdot questions are really getting stupid...

do you guys think i should wear a blue shirt tomarrow? ive heard alot of people like blue shirts but i was curious if anyone knew of any problems wearing blue shirts?

Re:bleh (0)

Anonymous Coward | more than 8 years ago | (#14820993)

whut do think of it ? fo shur slashdawt dawg! meh webtv taint runnin?

Re:bleh (1)

jalefkowit (101585) | more than 8 years ago | (#14826087)

Blue shirts should be fine. We have however had some problems reported by staff wearing red shirts. They keep getting sent to die at the hands of aliens. Keep this in mind when planning your wardrobe.

Not aliasing but multiple command multiple servers (1)

Wally4u (603232) | more than 8 years ago | (#14820955)

I think the author is looking for a way to run the same commands on multiple servers at the time to ease administraton. I should not that although the servers might be set up the same, running multiple commands on multiple servers can/is dangerous, since you don't see the results clearly. Quick google: http://tinyurl.com/sxfkh [tinyurl.com] http://tinyurl.com/qxr4n [tinyurl.com]

Re:Not aliasing but multiple command multiple serv (1)

after fallout (732762) | more than 8 years ago | (#14821147)

You could install and set up mpich2 (http://www-unix.mcs.anl.gov/mpi/mpich2/ [anl.gov]) and use it to run the same program on each computer seperately and output the results on the terminal that you entered the command.

ex. (get the hostname from 4 different computers)
#mpiexec -n 4 /bin/hostname
fred
frank
fluffy
twirl

This is most likely very overkill for what the author wants tho.

Absurd question (1)

HishamMuhammad (553916) | more than 8 years ago | (#14820978)

Mod me troll, I don't care, but I think Cliff should be ashamed of having posted this.

Re:Absurd question (0)

Anonymous Coward | more than 8 years ago | (#14829488)

I think that someone has finally made an automatic /. submission generator, similar to the automatic paper generator http://pdos.csail.mit.edu/scigen/ [mit.edu]. You can't blame Cliff for being duped into thinking there was actually a human behind this absurdity. It's a bunch of keywords thrown together to make it sound like there's actually a question:
      Windows
      1200 Linux Based Servers
      ssh
      alias
      remote server

MUD? (0)

Anonymous Coward | more than 8 years ago | (#14821008)

The only Widnows-based remote console clients I know of that support client-side aliases are the ones designed for MUDs.
alias fb="cast fireball at"
alias h="cast cure light wounds on"
fb rat
fb rat
h self
fb rat

Good idea (1)

benjamindees (441808) | more than 8 years ago | (#14821010)

I can see the benefits of such an arrangement.

But I see no benefits of staying on Windows. Bottom line: switch to Linux or BSD like everyone else managing multiple remote servers and reap the benefits. It's as simple as:

$ ssh remote.host "cd /home; pwd"

cygwin (0)

Anonymous Coward | more than 8 years ago | (#14823690)

$ ssh remote.host "cd /home; pwd"

Cygwin [cygwin.com] has command line ssh that will let you do this.

How about keyboard macro recording/playback? (1)

Richard Steiner (1585) | more than 8 years ago | (#14821095)

The use of command aliases is a good way reduce command complexity, thus reducing the number of typographical errors (and the resulting operational errors) when doing support.

That, by itself, could be a strong case for allowing an approved subset of aliases on your set of supported servers. Demonstrate a case where a simple typo could be catastrophic.

Typically, however, those aliases are resident in the shell local to the server, not in an ssh client (which usually provides pass-through access to the shell [and aliases] on the server).

If management is adverse to the idea of aliases for some reason, you might want to look at using a keystroke recording/playback utility to run on top of the ssh client. I've seen a number of those for Windows over the years.

What the heck do you mean with an "alias"? (1)

DrMorris (156226) | more than 8 years ago | (#14821490)

Maybe you are looking for a way to run a specific command without logging in? This can be done with key authorization. The command must be named before the key in authorized_keys (OpenSSH), which looks something like this:

command="/some/script/or/something.sh" ssh-rsa user@host

Clarification (1)

Meph_the_Balrog (796101) | more than 8 years ago | (#14821810)

Ok, my bad for attempting to keep the question "to the point".

Since I work in a corporate environment, my choice of workstation operating system is well beyond my control, even more so than my ability to deploy command aliases to each individual server. I'm also on helpdesk, so I have no direct administrative access, just a limited shell account that is shared between myself and 5 other techs. I could try and make a business case for command aliases being deployed to all the servers, but as a helpdesk tech, the chances of this idea being taken seriously are small. I'm sure any of you who have served time on the front lines understand what I mean.

Thanks for the feedback though guys, for the most part it has been most enlightening =).

Re:Clarification (1)

Seraphim_72 (622457) | more than 8 years ago | (#14822260)

Ahhh....Then I think the earlier comment about keyboard macros is apropos. My 2 cents is to run out and buy a Nostromo [belkin.com] if the let you install the software. The programming ability of the unit is amazing and it will allow you, once you get used to it to hit one key or a combo of keys to get things done. They are also cheeeeap! I have never tried one over putty, but I would imagine that it would still work. There are also keyboards with memory on them that dont need a software install, the ones I have seen have been godawful in price though. Plus there is macro software out there for windows that seems relativly cheap as well. Just google it [google.com]
Sera

Re:Clarification (0)

Anonymous Coward | more than 8 years ago | (#14824483)

I've replied to this [slashdot.org] with an answer. I'm really apalled, nay, aghast at the responses so far. Clearly very few people either a) understand your problem or b) have done any sort of large-scale system administration in their livess.

Repasting here because anonymously it's likely to be lost in the noise:

Tested this on linux, to linux, but I'm fairly confident any decent ssh
client could do this.
 
 
ssh -t localhost 'cp <(echo alias foo=bar; echo alias qux=baz; echo source ~/.bashrc) /tmp/myaliases.sh ; bash --init-file /tmp/myaliases.sh ; rm /tmp/myaliases.sh'
 

 
  What is this doing?
 
  1. ssh to localhost, but allocate a pty (the -t flag)
  2. Create a fifo in /dev/fd/whatever, then copy that to a real file in /tmp. For whatever reason bash won't execute an rcfile if it's a fifo.
  3. Note that our little script also sources ~/.bashrc so it acts like normal
  4. Startup bash pointed to our copy of our own aliases
  5. Yay! Interactive bash! Do whatever
  6. When we logout, the file is automatically cleaned up. Aww, aren't we courteous

 
Slashdot is really not a helpful place to ask.


To all the idi^H^H^Hslashdotters who clearly do not understand:

Why would anyone want to do this?

Imagine you're an administrator for 50 machines, with 7 other admins. Each machine as a plethora of role accounts for various facilities and daemons. You've carefully distributed everyone's public keys to the appropriate machines so nobody needs passwords, everyone just uses role accounts.

Imagine you're also a vi user. Imagine the rest of your admin team is a bunch of Emacs losers who can't vi their way out of a paper bag.

Imagine you add "set -o vi" to 50 ~/.bashrc

Imagine what your Emacs-weenie co-workers would do to you.

OK? Get the picture?

Re:Clarification (1)

Valdrax (32670) | more than 8 years ago | (#14828572)

I'm sorry that no one got what you were asking for, and I wish that I could help, but I'm in a similar boat with no paddle. Personally, I don't use aliases very much, but I've grown to hate ksh88 and miss my bash and tcsh so very much. (I want my command substitution and '!!' back!)

On the other hand, I have leared to stop worrying and love the vi mode.

Don't use Putty to ssh to nix boxen (1)

SpaceLifeForm (228190) | more than 8 years ago | (#14821812)

Unless you trust that the windows box is not ever going to grab your local keystrokes, capturing your username/password information for the nix boxen.

Not that I've tested this... (1)

Lord Bitman (95493) | more than 8 years ago | (#14822054)

try configuring the clients to set the environmental variable PROMPT_COMMAND to "eval alias dir='ls -l' ; eval alias del='rm -i' ; eval PROMPT_COMMAND="

</lame>

What he seems to be looking for... (1)

Synonymous Bosch (957964) | more than 8 years ago | (#14822082)

is a number of bash scripts on servers he manages that perform complex series of command line tasks with a single command executed by the helpdesk operator. Not a bad idea, as it eliminates the potential for human error by unskilled or unwary operators, but i can see why it wouldn't have been rolled out by the tech staff or approved by management: If i was a helpdesk operator in a company managing linux servers, my only way up the ladder would be by increasing my skillset in the managed environment. Having the hard work done for my by a simple script, and not having to take the responsibility for my actions in the environment means I dont personally develop in a technical capacity (the management reason). It also means they could replace me with someone with no skills whatsoever (the tech reason) Funny the tech reason is so brief compared to the management reason ;)

copy/paste (1)

fred fleenblat (463628) | more than 8 years ago | (#14822122)

sooo.... is anything stopping you from just pasting in a bunch of alias commands when you start the ssh session?

leave a notepad window open with the alias commands selected if you do it a lot.

Actually it seems like he is looking for is.... (1)

swordsaintzero (665343) | more than 8 years ago | (#14822262)

A ssh client that will let him alias bash commands client side. In other words he is not allowed to copy his tweaked out .bashrc to all the servers (1200 boxes apparently) and he wants his aliased commands to be the same no matter which box he logs into despite not having them setup in the local profile. Unfortunately I am not really sure how to do this, since I memorized the actual commands instead of aliasing things. *I probably should use alias more but meh.

Re:Actually it seems like he is looking for is.... (1)

Meph_the_Balrog (796101) | more than 8 years ago | (#14822713)

Please mod up - this is almost exactly what I was asking for =) (there are others who have said similar, but none quite so concise)

Re:Actually it seems like he is looking for is.... (1)

karlto (883425) | more than 8 years ago | (#14823138)

Well, if this is the case, then just find a similar approach to some of the other suggestions...

  1. create your alias script on the local machine
  2. copy/paste script into terminal OR record as macro OR something else similar
  3. run this macro/paste/whatever each time you log in to remote server

Once set up, step 3 should only be one extra click to save time and effort.

Or even better... (1)

metamatic (202216) | more than 8 years ago | (#14823227)

Keep the aliases in a file in your home directory. After login, source ~me/aliases

That way you don't need to worry about flaky cut/paste buffers.

(If you don't have a home directory because you're logging in straight to the root ID, then the sysadmins are clearly a bunch of idiots.)

Re:Actually it seems like he is looking for is.... (2, Informative)

^chewie (65165) | more than 8 years ago | (#14826426)

The type of interface you're thinking about is something along the lines of a text-based MUD or IRC client, where your commands are hooked BEFORE being sent to the server. I personally don't know of any, but can't imagine that it hasn't been considered. Currently, OpenSSH uses the "~" character to indicate that an SSH command will follow. "~C" drops you to an "ssh>" prompt to add things like tunneling while you're still connected to the host. Evidently, the ability to intercept input and redirect it to a local function is already built in to the software. IIRC, you can change the command character if "~" is too clunky for you. The next task is to extend this to provide an alias function. For example, you could bind "~a" to a theoretical "run-alias ALIAS ARGS" command. The desired effect is to output the expanded or constructed shell commands to the host. You will likely want to bind an interpreter to the run-alias command rather than creating your own. Find a license that is compatible with the OpenSSH client or whatever client you might be using.

What he's looking for.. (1)

kagaku (774787) | more than 8 years ago | (#14822318)

Since there seems to be some confusion as to what exactly he's asking for, here's my 'guess'. He manages these 1200 linux servers, and wants to use his commonly used aliases on all these boxes. Common sense says he has write access, he's just looking for a way to use his aliases across the entire network of servers, and not have to 'install' an alias file or whatnot everytime he logs in to a new box. I think he's asking for some way to store the aliases locally, so that when you type 'ls' into the SSH client, it sends 'ls -lah' to the remote server. Correct me if I'm wrong. *shrug*

Cut & Paste (1)

wayland (165119) | more than 8 years ago | (#14823029)

Here's a semi-automatic way of doing it:
1. Put all your alias commands in a text file on your Windows machine
2. After you log in to a machine, paste the text in at the prompt

Sure it's a pain, but it works. You could even put in something like:
cat >> .bash_profile
echo No Aliases Required
alias 'l=ls -a'
...
Then paste that in and press Ctrl+D. That way, it will put in the aliases each time you log in to that machine. If you don't see the message that says "No Aliases Required", then you know you need to paste them in.

Do it in the remote shell. (1)

munpfazy (694689) | more than 8 years ago | (#14823385)

Although I hesitate to offer any advice that will increase productivity in a company so unpleasant that they won't let their employees create .profile files, here's something that may work.

First of all, if you can possibly find a way to create your aliases within the shell of the remote machine, do so. There are two reasons:

1 - Only the remote shell knows enough about the context of your input to interpret aliases reliably. Your ssh client will be flying blind, and trying to get something that's functional enough to be useful and not dangerous will be tricky. Unless you do something very restrictive, such as making a special unique "I'm invoking an alias" command and then expanding the alias on the screen immediately, you're in for trouble. (One might argue that isn't really a proper alias at all, but rather a keystroke macro.) Anything more advanced will crash and burn the first time you try to open a file that happens to have the same name as one of your aliases.

If all you ever want to do is enter sequential shell commands, you could possibly fudge it by finding a way to send whole lines rather than characters to the remote machine and then moving all the readline stuff into your client. The out-of-the-box example would be running ssh within a shell within emacs. But, you'll lose meaningful tab completion and other context sensitive goodies, and it will break any program that needs to interact with a real terminal. And, you'll have to install custom software on the client machines, which one might expect to be a bigger deal than installing a single .profile file.

2 - The people who wrote your shell already worked out all the bugs when implementing aliases decades ago. You're less likely to find nasty surprises if you use a tool that's been used millions of times than something cobbled together by yourself. Sounds like nasty surprises aren't something your bosses will like.

Given that, here's one option that will probably work in most environments.

Create an ascii text file containing all your aliases in a format that can be evaluated without linebreaks. For a bash example, a series of lines such as the following:

        alias hihi='echo "this is an alias"';
        alias lt='ls -lrt';

Then put it on the web somewhere.

When you log in to the remote machine, run something like this (again using bash as an example):

eval `lynx -dump "http://someserver/somefile.bash.txt"`

Assuming the remote machine is connected to the web and has lynx, you're done. Make sure you read the output carefully at least once before you evaluate it in case there are any funny surprises due to line folding or nested quotes.

Now you've reduced things to typing in a single string every time you ssh in. There's probably some way to make a windows ssh client execute an arbitrary command and within an interactive shell, which could save you even that annoyance. (But it's been a long time since I've used windows, so I wouldn't have a clue how to do it. With openssh on a unix machine, it would be easy. I'm sure a windows equivalent exists.)

Good luck.

Alias Bad. Function Good. (1)

thedji (561789) | more than 8 years ago | (#14824102)

Server-side:

If you're using a shell that supports functions (i.e. bash), then you can get a lot more functionality by defining functions in your .[bash]rc file. For example:
function findhere() {
loc='.'
[ -n "$2" ] && loc=$2
find $loc -iname "*$1*"
}
...is one of many I use, 'find SOMEWHERE -iname "*PARTNAME*"' becomes 'findhere PARTNAME SOMEWHERE', with SOMEWHERE defaulting to the current dir.

Client-side:

Most SSH clients (i'm sure i'll get corrected) will not pre-process your standard text input before sending to the server (except maybe to fix up ^H's, etc), but many do offer programmable macros, similar to using functions in your shell's .rc file. I use PuTTY, which doesn't offer macros AFAIK, but this search [google.com] gives a shitload of results that might help you find some decent software.

What about cygwin on your windows desktop? (1)

elib (88805) | more than 8 years ago | (#14824239)

One easy way to accomplish this is to run cygwin http://www.cygwin.com/ [cygwin.com] on your windows box, setup all of your environment variables there (aliases and anything else you want), and have SSH pass your environment variables when connecting to a new box. With cygwin you get the standard openssh client, so anything you could do on a gnu box you can do there. You can get this all working and not have to change anything on the actual servers, it will all happen "automagically" on any server you log into, as long as sshd is setup to allow passing env. variables. Cygwin also lets you do all kinds of nifty things, like executing shell scripts from your windows box that log into the linux servers and execute commands. I've found that this is a great way to eliminate the human error factor when running identical commands on many servesr. Write a short script that will SSH in with SSH keys, run the script, verify the output/results and then display the results to the screen. Typically it doesn't save you too much time, as you need to write/test the script, but if can save you from making silly typos on production machines, and if your working on many servers, it can save time in the end. Nothing like a for do loop that iterates through all hosts and applies patches etc.

I also like one persons suggestion to put all the variables into a shell script on a webserver, and when you first log into a box you could just run wget -O - http://server/script.sh [server] | bash or something along those lines.

Aliases in themselves are not a risk, it's only when they are impoperly used. For example, aliasing rm -rf / to something your might accidentally type isn't a good idea. However, if used carefully they can be very convinient and save quite a bit of time. I used them extensivly in my early unix admin days, but I found that they only caused me pain later when I would work on a box without my aliases and I'd be constantly retyping things and trying to remember what the actual command that I wanted was that my alias ran. Similar to people who don't know anyone's phone numbers because they are all stored in their cell's memory. It's great until you don't have it any you don't know any numbers.

Re:What about cygwin on your windows desktop? (1)

munpfazy (694689) | more than 8 years ago | (#14824869)

setup all of your environment variables there (aliases and anything else you want), and have SSH pass your environment variables when connecting to a new box.


Hmmm. I've always thought of aliases and variables as very different sorts of beasts. Is there a way to manipulate aliases as though they were environment variables? (In one of the common shells?) Sounds like it could be a handy trick.

HERE'S THE ANSWER (0)

Anonymous Coward | more than 8 years ago | (#14824396)

This might also work using Cygwin's ssh. Tested this on linux, to linux, but I'm fairly confident any decent ssh client could do this.


ssh -t localhost 'cp <(echo alias foo=bar; echo alias qux=baz; echo source ~/.bashrc) /tmp/myaliases.sh ; bash --init-file /tmp/myaliases.sh ; rm /tmp/myaliases.sh'


What is this doing?
  1. ssh to localhost, but allocate a pty (the -t flag)
  2. Create a fifo in /dev/fd/whatever, then copy that to a real file in /tmp. For whatever reason bash won't execute an rcfile if it's a fifo.
  3. Note that our little script also sources ~/.bashrc so it acts like normal
  4. Startup bash pointed to our copy of our own aliases
  5. Yay! Interactive bash! Do whatever
  6. When we logout, the file is automatically cleaned up. Aww, aren't we courteous


Slashdot is really not a helpful place to ask.

version 1.1 (0)

Anonymous Coward | more than 8 years ago | (#14824586)

I realize now I was being too tricky, because in setting this up I was trying to get bash to read from a fifo, but that didn't work, so I gave up and just copied the fifo (dumb). This is probably better:

ssh -t localhost '(echo alias foo=bar; echo alias qux=baz; echo source ~/.bashrc)> /tmp/myaliases$$.sh ; bash --init-file /tmp/myaliases.sh ; rm /tmp/myaliases$$.sh'

version 1.2 (0)

Anonymous Coward | more than 8 years ago | (#14824683)


function s() {
        IFS=$'\n'
        unset profile
        for l in `cat ~/.bashrc`; do profile="$profile echo $l;"; done
        unset IFS
        ssh -t $1 '('"$profile"' echo source ~/.bashrc)> /tmp/myaliases$$.sh ; bash --init-file /tmp/myaliases$$.sh ; rm /tmp/myaliases$$.sh'
}


Now you just say:

s hostname

and there you go, logged into your host with your profile from your current host (not entirely complete if your profile sourced something). Play with it, I'm not a much of a shell hacker and I'm not writing a 1.3

The proper way to do this. (1)

c0nman (573940) | more than 8 years ago | (#14825332)

They have two options for this:

1) Cygwin
2) Dedicated Shell Server
Within this environment you will use fanout [stearns.org] from Bill Stearns [stearns.org]

A) If the remote systems are not set to ``UseLogin yes'' in sshd_config then the custom environment can be used with environment='whatever=whatever' in the remote ~/.ssh/authorized_keys. This, of course, would also require a key which may not be possible as well as ``PermitUserEnvironment yes'' set in sshd_config.

B) The env channel from the ssh client can set the environment on the remote system. This also will not work if ``PermitUserEnvironment no'' is set in sshd_config.

C) If ``PermitUserEnvironment yes'' is set then ~/.ssh/environment will also be evaluated upon login. This would not be advised as it appears as though multiple users aside from the admin's would be using the account(s).



Remember, A and B rely on C to work.

You will recieve the following if it is not setup correctly:
Server refused to set environment variables

Anyways, fanout is the method of choice for issuing commands across multiple servers at the same time while providing the output of those commands to the controling terminal. Just setup a few variables and include them in the remote command(s).

How about using expect? (1)

schlenk (941701) | more than 8 years ago | (#14825657)

If you don't like whats provided by your ssh client, how about wrapping a windows commandline ssh client like putty with Expect?
http://expect.nist.gov/ [nist.gov] for Expect and some usage examples
http://tcl.activestate.com/ [activestate.com] for Expect for Windows

Just define all the convenience functions you need as simple expect scripts and don't look back. If you like GUIs add some trivial Tk code.

expect (1)

leehwtsohg (618675) | more than 8 years ago | (#14825756)

expect can do what you want. You would start ssh inside expect, and program a simple script for expect so that it spews out the aliases at the right moment. The hardest part would be to find which of the 'expect's that exist for windows will do the job.

I don't know expect, but the script will probably look something like this:
spawn ssh [lindex $argv 1]
expect ">"
send "alias this=that"
send "alias ls=dir"
interact
Load More Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Sign up for Slashdot Newsletters
Create a Slashdot Account

Loading...