Install Zsh Without Root Access

Install zsh without root access?

You can try the chsh command. Are you sure zsh isn't installed on the distant computer? If not, you can do this (quoted from zsh FAQ Section 1.7)

The basic idea is to use exec to replace the current shell with zsh. Often you can do this in a login file such as .profile (if your shell is sh or ksh) or .login (if it's csh). Make sure you have some way of altering the file (e.g. via FTP) before you try this as exec is often rather unforgiving.

If you have zsh in a subdirectory bin of your home directory, put this in .profile:

[ -f $HOME/bin/zsh ] && exec $HOME/bin/zsh -l

or if your login shell is csh or tcsh, put this in .login:

if ( -f ~/bin/zsh ) exec ~/bin/zsh -l

(in each case the -l tells zsh it is a login shell).

If you want to check this works before committing yourself to it, you can make the login shell ask whether to exec zsh. The following work for Bourne-like shells:

[ -f $HOME/bin/zsh ] && {
echo "Type Y to run zsh: \c"
read line
[ "$line" = Y ] && exec $HOME/bin/zsh -l
}

and for C-shell-like shells:

if ( -f ~/bin/zsh ) then
echo -n "Type Y to run zsh: "
if ( "$<" == Y ) exec ~/bin/zsh -l
endif

It's not a good idea to put this (even without the -l) into .cshrc, at least without some tests on what the csh is supposed to be doing, as that will cause every instance of csh to turn into a zsh and will cause csh scripts (yes, unfortunately some people write these) which do not call csh -f to fail. If you want to tell xterm to run zsh, change the SHELL environment variable to the full path of zsh at the same time as you exec zsh (in fact, this is sensible for consistency even if you aren't using xterm). If you have to exec zsh from your .cshrc, a minimum safety check is if ($?prompt) exec zsh.

If you like your login shell to appear in the process list as -zsh, you can link zsh to -zsh (e.g. by ln -s ~/bin/zsh ~/bin/-zsh) and change the exec to exec -zsh. (Make sure -zsh is in your path.) This has the same effect as the -l option.

Footnote: if you DO have root access, make sure zsh goes in /etc/shells on all appropriate machines, including NIS clients, or you may have problems with FTP to that machine.

How can I get a secure system-wide oh-my-zsh configuration?

Fair Warning: this assumes a Debian style linux, but this should work on other forms as well. This also assumes you are starting from scratch.

Part 1, the install:

You will need to install zsh system wide, and not just for one user. (you may have already done this but I'll include it just to be comprehensive)

make sure you have installed zsh, simply: sudo apt-get install zsh

Follow the oh-my-zsh install guide or you can either:

use curl

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

use wget

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

Part 2, Setting up zsh when new users are added:

You will need to make it so that new users default to zsh. In your /etc/adduser.conf file edit the line that says:

DSHELL=/bin/sh

to:

DSHELL=/bin/zsh

You should also change it for the /etc/default/useradd file, change the line:

SHELL=/bin/sh

to:

SHELL=/bin/zsh

Part 3, set your custom theme.

I have a custom theme file (here) that I wanted all users on the system to have. First, you should add the file to your .oh-my-zsh/themes folder:

cp your_custom_style.zsh-theme ~/.oh-my-zsh/themes

Next, edit your .zshrc file in your home directory, change the ZSH_THEME="default" to ZSH_THEME="your_custom_style"

Then, reload your .zshrc file with: . ~/.zshrc

Part 4, setting up new user's home directories.

We need to to place whatever files we want the new users to have in the /etc/skel directory, because this is what the system copies when it is creating new user's home directory. See this sys admin guide for details.

Copy your user's files (you may need to sudo):

cp -r .oh-my-zsh /etc/skel/
cp .zshrc /etc/skel

Now you will be able to add new users and they will have oh-my-zsh by
default with whatever custom theme you want them to have.

If you want to change all other existing user's shell to zsh, I would recommend reading this serverfault question.

installing oh-my-zsh for a different user as root in cloud-init script

I solved this thanks to jgshawkey's answer here. I used bash variables to escape the color codes & commands to postpone their evaluation:

  - apt-get install -y zsh
- runuser -l ubuntu -c 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/coreycole/oh-my-zsh/master/tools/install.sh)"'
- chsh -s $(which zsh) ubuntu
- fgGreen='%{$fg[green]%}'
- fgCyan='%{$fg[cyan]%}'
- fgReset='%{$reset_color%}'
- retStatus='${ret_status}'
- gitInfo='$(git_prompt_info)'
- runuser -l ubuntu -c "echo export PROMPT=\''${fgGreen}%n@%m${fgReset} ${retStatus} ${fgCyan}%c${fgReset} ${gitInfo}'\'" >> /home/ubuntu/.zshrc
- echo "source ~/.profile" >> /home/ubuntu/.zshrc

It ended up looking like this in my ~/.zshrc:

Sample Image

How do I set the default .zshrc (oh-my-zsh) for users?

oh-my-zsh is best installed per user. Users can fiddle with the source, adding custom plug-ins to their .oh-my-zsh/custom directory for instance. The auto-update feature also wouldn't work on a system wide install.

To help them get started, you can provide new users with a recent clone of .oh-my-zsh and a .zshrc template. Adding these to /etc/skel for instance.

I'd also question whether root needs oh-my-zsh or the same zsh config as a normal user. It's best to avoid spending too much time as root anyways.

If you really want to, you can symlink your own .oh-my-zsh and .zshrc to another user home directory including root's.

If you have to enforce a global config. There's a global zshrc (either /etc/zshrc or /etc/zsh/zshrc depending on your system) that's loaded before the user .zshrc. If you're impersonating all users on the system, you could always load your oh-my-zsh config from there.

Finally, you'll probably want to change the login shell of oh-my-zsh user to zsh as well. Look into /etc/passwd, chsh and adduser.conf for details.

What is the correct setup for Brew + Zsh + Oh My Zsh on multiple admin users on Mac OS X?

Although this step is safe to run as root, I still recommend running the installation as non-root user to prevent catastrophic problems with root switching shell while the shell isn't working. superuser shell should never be changed.

Here's the proper way to install oh-my-zsh for multiple users.

Step 1: Ensure umask is not stricter than 022. If not set it to 022.

$ umask 022

Step 2: set and export ZSH with the destination path where the shared oh-my-zsh will be installed.

export ZSH=/usr/local/.zsh/oh-my-zsh

Step 3: Create the parent directory and make it owned by the user installing the scripts.

$ sudo mkdir /usr/local/.zsh
$ sudo chown ${USER} /usr/local/.zsh

Step 4: Run the installer.

$ bash -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Step 5: Change ownership of the installation path back to root.

$ sudo chown -R root /usr/local/.zsh

Step 6: Update location of ZSH in ${ZSH}/templates/zshrc.zsh-template

$ sudo sed -i 's|export ZSH=.*|export ZSH='${ZSH}'|' ${ZSH}/templates/zshrc.zsh-template

(Optional)
Step 7: Disable auto update. This is recommended as the installation is now owned by root.

$ sudo sed -i 's/# DISABLE_AUTO_UPDATE="true"/DISABLE_AUTO_UPDATE="true"/' ${ZSH}/templates/zshrc.zsh-template

From here on, each user can copy ${ZSH}/templates/zshrc.zsh-template as ~/.zshrc

How to install packages in Linux (CentOS) without root user with automatic dependency handling?

It is possible to use yum and rpm to install any package in the repository of the distribution. Here is the recipe:

Find the package name

Use yum search.

Download

Download the package and all of its dependencies using yumdownloader (which is available on CentOS by default). You'll need to pass it --resolve to get dependency resolution. yumdownloader downloads to the current directory unless you specify a --destdir.

mkdir -p ~/rpm
yumdownloader --destdir ~/rpm --resolve vim-common

Choose a prefix location

It might be ~, ~/centos, or ~/y. If your home is slow because it is on a network file system, you can put it in /var/tmp/....

mkdir ~/centos

Extract all .rpm packages

Extract all .rpm packages to your chosen prefix location.

cd ~/centos && rpm2cpio ~/rpm/x.rpm | cpio -id
  • rpm2cpio outputs the .rpm file as a .cpio archive on stdout.
  • cpio reads it from from stdin
  • -i means extract (to the current directory)
  • -d means create missing directory

You can optionally use -v: verbose

Configure the environment

You will need to configure the environment variable PATH and LD_LIBRARY_PATH for the installed packages to work correctly. Here is the corresponding sample from my ~/.bashrc:

export PATH="$HOME/centos/usr/sbin:$HOME/centos/usr/bin:$HOME/centos/bin:$PATH"

export MANPATH="$HOME/centos/usr/share/man:$MANPATH"

L='/lib:/lib64:/usr/lib:/usr/lib64'
export LD_LIBRARY_PATH="$HOME/centos/usr/lib:$HOME/centos/usr/lib64:$L"

Edited note (thanks to @AmitNaidu for pointing out my mistake):

According to bash documentation about startup files, when connecting to a server via ssh, only .bashrc is sourced:

Invoked by remote shell daemon

Bash attempts to determine when it is being run with its standard input connected to a network connection, as when executed by the remote shell daemon, usually rshd, or the secure shell daemon sshd. If Bash determines it is being run in this fashion, it reads and executes commands from ~/.bashrc, if that file exists and is readable.


Now if you want to install a lot of packages that way, you might want to automate the process. If so, have a look at this repository.


Extra note: if you are trying to install any of gcc, zlib, make, cmake, git, fish, zsh or tmux , you should really consider using conda, see my other answer.

Installing Git with non-root user account

You can download the git source and do ./configure --prefix=/home/user/myroot && make && make install to install git to your home directory provided you have the build tools. If you don't have the build-essential package installed (dpkg --list|grep build-essential), you will need to install those to your home directory as well.

Command not found - Oh-My-Zsh

Question:

➜ ~ mvn

zsh: command not found: mvn

Answer:

step 1:

    vim ~/.zshrc

step 2:(Add at the end of the file)

    source ~/.bash_profile;

step 3:(Execution shell)

    > source ~/.bash_profile

You can use mvn :

➜ / mvn

[INFO] Scanning for projects...
.......



Related Topics



Leave a reply



Submit