Skip to content

Commit d15e2df

Browse files
authored
Create read-only-ssh-user.sh
1 parent 044ec25 commit d15e2df

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

read-only-ssh-user.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# The below is run as root user (or sudo user) and tested on Ubuntu Machine
4+
5+
# Create a User with restricted bash shell
6+
useradd -s /bin/rbash -m "$USERNAME"
7+
mkdir /home/"$USERNAME"/.ssh/
8+
9+
# Copy the pubkeys here and change permissions
10+
cd /home/"$USERNAME"/
11+
cat /tmp/"$PUBLIC_KEY" >> .ssh/authorized_keys
12+
chmod 0700 .ssh/
13+
chown -R "$USERNAME":"$USERNAME" .ssh
14+
15+
# remove temp keys
16+
# Add command symlinks to the user private bin dir
17+
cd /home/"$USERNAME"
18+
mkdir bin
19+
20+
ln -s /bin/ls /home/"$USERNAME"/bin/
21+
ln -s /usr/bin/top /home/"$USERNAME"/bin/
22+
ln -s /usr/bin/du /home/"$USERNAME"/bin/
23+
ln -s /bin/date /home/"$USERNAME"/bin/
24+
ln -s /bin/uname /home/"$USERNAME"/bin/
25+
ln -s /usr/bin/free /home/"$USERNAME"/bin/
26+
ln -s /usr/bin/head /home/"$USERNAME"/bin/
27+
ln -s /usr/bin/tail /home/"$USERNAME"/bin/
28+
ln -s /usr/bin/less /home/"$USERNAME"/bin/
29+
ln -s /bin/more /home/"$USERNAME"/bin/
30+
ln -s /bin/cat /home/"$USERNAME"/bin/
31+
ln -s /bin/ping /home/"$USERNAME"/bin/
32+
ln -s /usr/bin/telnet /home/"$USERNAME"/bin/
33+
34+
# Update path and deny path editing for "$USERNAME"
35+
cd /home/"$USERNAME"
36+
sed -i '/^PATH/s/PATH.*/PATH=\$HOME\/bin/g' .profile
37+
sed -i '/^PATH/s/PATH.*/PATH=\$HOME\/bin/g' .bashrc
38+
chattr +i .bashrc .profile

0 commit comments

Comments
 (0)